Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Sep 2009
    Posts
    57
    Thanks
    6
    Thanked 0 Times in 0 Posts

    move_uploaded_file() error

    Hi. While trying to test a some code, I ran into this error:
    Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to access Resource id #3/eroare.php in /home/www/free/uv.ro/rudolf.uv.ro/php/upload.php on line 10
    The code is:
    Code:
    <?php
    require("class.easyzip.php");
    $timp=time();
    $zip=new EasyZIP;
    $file_dir="./upload".$timp;
    mkdir($file_dir, 0777);
    $dir=opendir($file_dir);
    foreach($_FILES as $fisier=>$fisiere)
    	{if(is_uploaded_file($fisiere['tmp_name']))
    		{move_uploaded_file($fisiere['tmp_name'], "$dir/$fisiere[name]");}}
    while(!(($fisier=readdir($dir))===false))
    	{$zip->addFile($fisier);}
    closedir($dir);
    Does anyone know what the problem might be? Thank you.

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    You're trying to use the variable $dir in your filename but $dir is merely a pointer to a directory resource, it's not the actual name of a directory. To get that, you must use the readdir() function (as your code does on the next line).

  • #3
    New Coder
    Join Date
    Sep 2009
    Posts
    57
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fumigator View Post
    You're trying to use the variable $dir in your filename but $dir is merely a pointer to a directory resource, it's not the actual name of a directory. To get that, you must use the readdir() function (as your code does on the next line).
    uhmm....sorry for asking this, but can you make the necessary modifications to my code, please? I'm not that familiar with the readdir function....thank you very much.

  • #4
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Quote Originally Posted by speedy_rudolf View Post
    uhmm....sorry for asking this, but can you make the necessary modifications to my code, please? I'm not that familiar with the readdir function....thank you very much.
    Here's the manual page:

    http://us3.php.net/manual/en/function.readdir.php

  • #5
    New Coder
    Join Date
    Sep 2009
    Posts
    57
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Fumigator View Post
    Yeah....I still don't understand how to use it....I tried:
    Code:
    mkdir($file_dir, 0777);
    $dir=opendir($file_dir);
    foreach($_FILES as $fisier=>$fisiere)
    	{if(is_uploaded_file($fisiere['tmp_name']))
    		{move_uploaded_file($fisiere['tmp_name'], readdir($dir)."/$fisier[name]");}}
    And about 5 other combinations I could think of, but nothing works....
    Well...the code I posted seemes to be on the right track, because it copied one of two files, but named it F ...no extension...and it wasn't even in the right folder (it wasn't in the folder just created, it was in the "source" dir...the one where the php file is)...anyway...if you can at least point me in the right direction....Any tip will be very much appreciated....Thank you.
    Last edited by speedy_rudolf; 10-29-2009 at 07:59 AM.

  • #6
    New Coder
    Join Date
    Sep 2009
    Posts
    57
    Thanks
    6
    Thanked 0 Times in 0 Posts
    I just tried this code:
    Code:
    mkdir($file_dir, 0777);
    $dir=opendir($file_dir);
    $dir2=readdir($dir);
    foreach($_FILES as $fisier=>$fisiere)
    	{if(is_uploaded_file($fisiere['tmp_name']))
    		{move_uploaded_file($fisiere['tmp_name'], "$dir2/$fisier[name]");}}
    And it didn't give me an error message (like the one above), but the file problem remains (it still uploaded just one file named F with no extension in the wrong directory).
    Last edited by speedy_rudolf; 10-29-2009 at 08:04 AM.

  • #7
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    There is a concept here I think you're missing. You use opendir() to open the directory list as if it were a text file you're opening. Then you LOOP through this "file" of directory names, reading each name as you go, using readdir().

    I guess I assumed this was something you understood since your code is doing this loop with readdir() just below the move_uploaded_dir() call. And, speaking of that, you'll need to reset the file pointer or that code will no longer work the same way, since you are now calling readdir() once prior to entering that read loop.

    Perhaps you should reconsider the logic of your code.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •