#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    129
    Rep Power
    11

    Permission Denied to copy file (upload)


    Hi I am trying to upload several images to a user directory. I am using Windows XP home and I installed WAMP5 on my machine.
    Everything seems to work but the files wont copy to their intended directory and I get this error:
    Warning: copy(C:\wamp\www\dissertation\images\dan) [function.copy]: failed to open stream: Permission denied in c:\wamp\www\dissertation\functions\Image\upload_image.php on line 18

    Code:
    <b>Upload image</b><br />
    	<?php
    	for($i=1; $i<=10; $i++){
    	echo "Select image $i: <input type=file name='images[]' class='bginput'><br />";
    	}
    	?>
    	<input type="submit" value="Upload">
    	</form></p>
    PHP Code:
    @session_start();
    while(list(
    $key,$value) = each($_FILES[images][name]))
    {
        if(!empty(
    $value)) //check if a field is blank
        
    {   
                
                
    $filename $value;    // filename stores the value
                
                //Create User Image Directory
                
    $userdir $_SESSION['valid_user'];
                
    $uploaddir 'C:\wamp\www\dissertation\images\\'.$userdir;
                @
    mkdir ($uploaddir,0777);
                @
    chdir('./');
                
    copy($_FILES[images][tmp_name][$key], $uploaddir);   
            }

    The directory gets created just the copy function wont write. what do i need to do? configure something in apache? or in windows?
    noob is confused.
  2. #2
  3. blah
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Scotland
    Posts
    630
    Rep Power
    106
    look up the chmod function on php.net

    fire
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    129
    Rep Power
    11
    Originally Posted by fireatwill
    look up the chmod function on php.net

    fire
    but when i am creating the directory i am already doing 0777 which is rwx etc.
    and
    chmod("$uploaddir", 0777);

    does make no difference. I think it has to do with windows.. anyone??? HELP
  6. #4
  7. Rocking my php-ness
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Boston, MA
    Posts
    1,968
    Rep Power
    151
    Doesn't the file with the chmod() call need to be chmod to 666 first? I can never remember
    My new WebComic http://www.jjsunshines.com/
    The Geek Shall Inherit the Earth

    It is NOT ok to IM me with questions unless I told you it was ok via PM
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    129
    Rep Power
    11
    Originally Posted by J_Tree
    Doesn't the file with the chmod() call need to be chmod to 666 first? I can never remember
    chmond doesnt work in windows.

    Anyway even with a simple 1 file upload and one copy command into a directory which exist i get this error.

    surely there is something in apache or php so i can write files. I googled but cant find anything for windows
  10. #6
  11. Rocking my php-ness
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Boston, MA
    Posts
    1,968
    Rep Power
    151
    Originally Posted by Germanjulian
    chmond doesnt work in windows.

    Anyway even with a simple 1 file upload and one copy command into a directory which exist i get this error.

    surely there is something in apache or php so i can write files. I googled but cant find anything for windows

    http://64.233.179.104/search?q=cache...+windows&hl=en

    Read the user comments on the manual. The link shows google's cached results for php, chmod(), windows
    My new WebComic http://www.jjsunshines.com/
    The Geek Shall Inherit the Earth

    It is NOT ok to IM me with questions unless I told you it was ok via PM
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    129
    Rep Power
    11
    Originally Posted by J_Tree
    http://64.233.179.104/search?q=cache...+windows&hl=en

    Read the user comments on the manual. The link shows google's cached results for php, chmod(), windows
    thanks for the help but
    PHP Code:
                $userdir $_SESSION['valid_user'];
                
    $uploaddir 'C:\wamp\www\dissertation\images\\'.$userdir;
                @
    mkdir ($uploaddir,666);
                @
    chdir('./');
                
    chmod($_FILES[images][tmp_name][$key],666); 
    doesnt work either. man why did it work at work 1 year ago and not at home
  14. #8
  15. Rocking my php-ness
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Boston, MA
    Posts
    1,968
    Rep Power
    151
    Does the php file that contains the above script have permission to write files?
    My new WebComic http://www.jjsunshines.com/
    The Geek Shall Inherit the Earth

    It is NOT ok to IM me with questions unless I told you it was ok via PM
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    129
    Rep Power
    11
    Originally Posted by J_Tree
    Does the php file that contains the above script have permission to write files?
    ?
    huh?

    its not read only! just a normal windows. I even tried several examples from the net and i get the same error.
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Sep 2002
    Posts
    679
    Rep Power
    19
    Windows XP home? Not a production server then, so what I have had to do in the past on Windows is to share the folder that I'm trying to save the file to, and check the box that says something like "allow network users to change my files". Thats about the limit of what I know about Windows file/folder permissions, but worked for me.
  20. #11
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2004
    Posts
    3
    Rep Power
    0
    Mate, I've had the same problem and it was driving me nuts and IIS help documentation is worse than useless, but the but the share folder and tick 'allow network users to change my files' trick worked !!!

    Cheers!
  22. #12
  23. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2004
    Posts
    12
    Rep Power
    0
    I'm having the same problem. I wrote a website about a year ago & it still works using practically the same code as I'm using now.

    Now I get the error of:
    Code:
    Warning: move_uploaded_file(logos/paul.png): failed to open stream: Too many open files in (address here)/processUpload.php on line 34
    
    Warning: move_uploaded_file(): Unable to move '/tmp/phptOUh7j' to 'logos/paul.png' in (address here)/processUpload.php on line 34
    This is incredibly frustrating & it works on my localhost every time (Windows XP with IIS 5.0), but when it is on the host (Linux machine), it won't work.

    I tried removing my code that checks the database to see if they're logged in, and that worked. It's like PHP is overloaded or something, and I still don't have it working if I have to make sure the person is logged in. And no, the log in is not the problem.
  24. #13
  25. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Location
    PBC Clubhouse
    Posts
    75
    Rep Power
    12

    same problem but with the hosting site


    The copy function works fine when I run it in my local pc but when I uploaded it to the host site, it displays the permissino denied error. Do I need to contact the host company or will the chmod function suffice? What if it asks for a password? Below is my code for your perusal.

    /-- RE-SIZING UPLOADED IMAGE

    /*== only resize if the image is larger than 110 x 200 ==*/
    $imgsize = getimagesize($imgfile);
    /*== check size 0=width, 1=height ==*/
    if (($imgsize[0] > 110) || ($imgsize[1] > 105))
    {
    /*== temp image file -- use "tempnam()" to generate the temp
    file name. This is done so if multiple people access the
    script at once they won't ruin each other's temp file ==*/
    $tmpimg = tempnam("/tmp", "MKUP");

    /*== RESIZE PROCESS
    1. decompress jpeg image to pnm file (a raw image type)
    2. scale pnm image
    3. compress pnm file to jpeg image
    ==*/

    /*== Step 1: djpeg decompresses jpeg to pnm ==*/
    system("djpeg $imgfile >$tmpimg");


    /*== Steps 2&3: scale image using pnmscale and then
    pipe into cjpeg to output jpeg file ==*/
    system("pnmscale -xy 110 105 $tmpimg | cjpeg -smoo 10 -qual 50 >$imgfile");

    /*== remove temp image ==*/
    unlink($tmpimg);

    }

    /*== setup final file location and name ==*/
    /*== change spaces to underscores in filename ==*/
    $final_filename = $uploaddir.str_replace(" ", "_", $imgfile_name);
    $newfile = $final_filename;
    /*== do extra security check to prevent malicious abuse==*/
    if (is_uploaded_file($imgfile))
    { chmod($imgfile, 0777);
    /*== move file to proper directory ==*/
    if (!copy($imgfile,"$newfile"))
    {
    /*== if an error occurs the file could not
    be written, read or possibly does not exist ==*/
    print "<br>Error Uploading File.";
    exit();
    }
    }

    /*== delete the temporary uploaded file ==*/
    unlink($imgfile);

IMN logo majestic logo threadwatch logo seochat tools logo