...

View Full Version : move_uploaded_file() error



speedy_rudolf
10-28-2009, 08:11 PM
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:

<?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.

Fumigator
10-28-2009, 08:49 PM
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).

speedy_rudolf
10-28-2009, 09:02 PM
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.

Fumigator
10-28-2009, 10:49 PM
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

speedy_rudolf
10-29-2009, 08:36 AM
Here's the manual page:

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

Yeah....I still don't understand how to use it....I tried:

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.

speedy_rudolf
10-29-2009, 08:58 AM
I just tried this 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).

Fumigator
10-29-2009, 06:01 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum