move_uploaded_file returns False

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Bitweiser
Forum Newbie
Posts: 11
Joined: Sun Jul 30, 2006 9:27 am

move_uploaded_file returns False

Post by Bitweiser »

Huy guys,

I've got a strange thing going on. I'm trying to upload a file to a directory called "uploads". When the code is installed on my first server, everything is working fine. On the second test server I've got an error. Both servers are windows NT/XP servers.

Here's the code:

Code: Select all

$target_path = "../../images/uploads/";
$uploadfile = $target_path . basename($_FILES['uploadedfile']['name']); 
if  (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $uploadfile)) 
  echo "everything ok"                                                                  
else echo "error" ;
This is the output of print_r($_FILES);:

Code: Select all

Array
(
    [uploadedfile] => Array
        (
            [name] => testfile.jpg
            [type] => image/pjpeg
            [b][tmp_name] => .\php16.tmp[/b]
            [error] => 0
            [size] => 20752
        )
)
I'm guessing the problem lies in the temp file. Where the hell is ".\" coming from?

Anyone?

TIA
Last edited by Bitweiser on Mon Jul 31, 2006 11:51 am, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

your code uses uploadedfile, while the output shows uploadedfile1, typo?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Unlikely this is the original code, there's a syntax error.
Why not just copy&paste the real one?

What about the paths?
And error reporting?

Code: Select all

error_reporting(E_ALL);
ini_set('display_errors', true);

$target_path = "../../images/uploads/";
$uploadfile = $target_path . basename($_FILES['uploadedfile']['name']);

if (!is_dir($target_path)) {
	echo '<div>Debug: ', $target_path, ' is not a directory', "<div />\n";
}
if (!is_writable($target_path)) {
	echo '<div>Debug: ', $target_path, ' is not writable', "<div />\n";
}
if (!is_file($_FILES['uploadedfile']['tmp_name'])) {
	echo '<div>Debug: ', $_FILES['uploadedfile']['tmp_name'], ' file not found', "<div />\n";
}
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Post by daedalus__ »

What's error?
Bitweiser
Forum Newbie
Posts: 11
Joined: Sun Jul 30, 2006 9:27 am

Post by Bitweiser »

feyd wrote:your code uses uploadedfile, while the output shows uploadedfile1, typo?
Yep typo...I've changed it..
Bitweiser
Forum Newbie
Posts: 11
Joined: Sun Jul 30, 2006 9:27 am

Post by Bitweiser »

volka wrote:What about the paths?
And error reporting?

Code: Select all

if (!is_file($_FILES['uploadedfile']['tmp_name'])) {
	echo '<div>Debug: ', $_FILES['uploadedfile']['tmp_name'], ' file not found', "<div />\n";
}
This returns "Debug: .\php19.tmp file not found"
But I can't see why? The directory exists (proof is_dir) and it's writable (proof is_writable).
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

And is there a php19.tmp in this directory?

./ is very strange for $_FILES...tmp_name
Bitweiser
Forum Newbie
Posts: 11
Joined: Sun Jul 30, 2006 9:27 am

Post by Bitweiser »

volka wrote:And is there a php19.tmp in this directory?

./ is very strange for $_FILES...tmp_name
Well eh... no (I guess not) because php returns file not found.
Indeed ./ is strange but why is it there and what can I do about it.
Perhaps a php.ini config problem ? Or Apache ?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

There is a configuration directive for the temp directory: http://de2.php.net/manual/en/ini.core.p ... ad-tmp-dir
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Post by daedalus__ »

yeah.. you should probably set that if it isn't i had trouble with that the other day
Post Reply