Page 1 of 1

move_uploaded_file returns False

Posted: Mon Jul 31, 2006 10:58 am
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

Posted: Mon Jul 31, 2006 11:01 am
by feyd
your code uses uploadedfile, while the output shows uploadedfile1, typo?

Posted: Mon Jul 31, 2006 11:06 am
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";
}

Posted: Mon Jul 31, 2006 11:37 am
by daedalus__
What's error?

Posted: Mon Jul 31, 2006 11:51 am
by Bitweiser
feyd wrote:your code uses uploadedfile, while the output shows uploadedfile1, typo?
Yep typo...I've changed it..

Posted: Mon Jul 31, 2006 12:34 pm
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).

Posted: Mon Jul 31, 2006 12:41 pm
by volka
And is there a php19.tmp in this directory?

./ is very strange for $_FILES...tmp_name

Posted: Mon Jul 31, 2006 12:45 pm
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 ?

Posted: Mon Jul 31, 2006 12:55 pm
by volka
There is a configuration directive for the temp directory: http://de2.php.net/manual/en/ini.core.p ... ad-tmp-dir

Posted: Mon Jul 31, 2006 1:47 pm
by daedalus__
yeah.. you should probably set that if it isn't i had trouble with that the other day