Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

File Permissions - Can't Delete
  • Hello,

    I searched but cant find a solution.

    Is there a way to set file permissions of uploaded files?

    All the files i upload i cannot remove/delete via FTP or PHP.

    Please advise - thanks.
  • you can change permissions using chmod in your php script. Google 'chmod php' and you'll find plenty of examples. But is sounds like you want to change the owner of the file. In which case you would want to use 'chown'. chown is rarely used because the file must be owned by the user which is running the process and can create a security hole.
  • Gotcha, but where do i add that at?

    Didn't really see anywhere in upload.php where i could chmod the uploaded file.

    Thanks!
  • You put after the move_uploaded_file()
    [code=php]<?php<br />if (!empty($_FILES)) {
        $tempFile = $_FILES['Filedata']['tmp_name'];
        $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_GET['folder'] . '/';
        $targetFile =  str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];
        
        
    // Uncomment the following line if you want to make the directory if it doesn't exist
        // mkdir(str_replace('//','/',$targetPath), 0755, true);
        
        move_uploaded_file
    ($tempFile,$targetFile);
        chmod($targetFile, 0755);
    }
        
    echo 
    '1';

    ?>[/code]
  • That's simple enough, but i am still getting the errors.

    It seems like it's auto making the file owner 'apache'. Chmod works to change the file permissions but i still cant delete it and gives me 550 Permission Denied. Also tried Chown, but doesnt seem to do anything as well.

    Strange because i currently use SWFUpload and that works without a problem.

    Any other ideas i could try?
  • I take it then your running this on a local server. If your on a remote server you should go back to your web host. any php calls should be recorded against your user account not apache. I don't know how to change it for a local server.

    Uploadify doesn't have anything to do with file permissions, owner or group settings of files. This is all controlled by the server settings and calls such as chmod. If your script for SWFUpload is working without a hitch then you should be able to use that instead of the default uploadify script.

    I'm also assuming when you tried to delete the file via php you were using the unlink().
  • Thanks Travis.

    It's on a remote server running Plesk. I have contacted support but they can only really fix the permissions on the already uploaded files - not fix the issue.

    Any advice on how i can use the SWFUpload'er instead of Uploadify?

    I love how Uploadify works on the frontend, but as far as the backend - i dont care how it works as long as it does.
  • SWFUploader doesn't give you any actual working upload scripts. Can you post the code currently contained in the SWFUploader script your using. It should be just a matter of removing some lines.
  • File attached.

    I really appreciate your help. I know some PHP so you can just give me some direction it would help!
  • Still have no idea why SWFupload works fine, but have problems with Uploadify. Seems strange.
  • Doing some searching I found this on php's website under move_uploaded_file. I don't know if it applies to you
    For those using PHP on Windows and IIS, you SHOULD set the "upload_tmp_dir" value in php.ini to some directory around where your websites directory is, create that directory, and then set the same permissions on it that you have set for your websites directory. Otherwise, when you upload a file and it goes into C:\WINDOWS\Temp, then you move it to your website directory, its permissions will NOT be set correctly. This will cause you problems if you then want to manipulate that file with something like ImageMagick's convert utility.


    Also many people in that forum, experiencing a similar problem to you said using copy instead of move_uploaded_file fixed their issue.

    Lastly, I have found that apparently the user that runs the php scripts can be set in httpd.conf In my quick look I didn't find the settings, but if you do look and find it, set it to 'nobody' and then you should be able to delete files created with move_uploaded_file.

    Regarding the script you posted:

    There is nothing in the SWFUploader script you posted that affects permissions, owner or group of files uploaded. It just contains a shit load of sever checks that the file is valid.

    To get this script to work with uploadify
    1. delete the session cookie workaround or create a PHP session and pass it using scriptData, lines 4-10
    2. if your not passing 'id' 'through scriptData delete lines 12 -22
    3. If your not passing 'type' through scriptData delete lines 37-45
    4. make sure you correct any $folder and $theid references if you deleted the any of the above code
    5. Should an error occur HandleError will only generate a IO Error 2038.
  • To get this script to work with uploadify
    1. delete the session cookie workaround or create a PHP session and pass it using scriptData, lines 4-10
    2. if your not passing 'id' 'through scriptData delete lines 12 -22
    3. If your not passing 'type' through scriptData delete lines 37-45
    4. make sure you correct any $folder and $theid references if you deleted the any of the above code
    5. Should an error occur HandleError will only generate a IO Error 2038.




    thank you for sharing the information with us.
    But I am not sure where i can find the file that you mentioned and what is the file name, because I want passing 'type' through scriptData .
    look forward to your answer...
  • @jolie0001 The section of the post you are referencing is specifically for user deez.
  • hi.TravisN. thank you for your replying,I found another way to append a despcription by onSelect,then through scriptData to insert the value into db,but the value in db is [object],do you know how to solve the problem?
  • Thanks for the help Travis.

    Finally got it working.