Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File upload problem ... 1

Status
Not open for further replies.

dbeezzz

Technical User
Nov 30, 2005
54
KR
So I'm trying to upload a file to my php server but the move_uploaded_file() function keeps just returning false. I'm working on windows/apache.
This is my $_FILES array
Code:
[fileupload] => Array
        (
            [name] => spacer.gif
            [type] => image/gif
            [tmp_name] => /tmp\php154.tmp
            [error] => 0
            [size] => 43
        )
... the tmp filename seems to be illegal. But I don't know how to get around it if that really is the problem. I've tried changing around the files and folders, and uploading .jpg files instead of .gif but no luck ...
 
oh, and here is my code ... taken almost straight from the php manual
Code:
$uploaddir = './';
	$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
	
	echo '<pre>';
	if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
   		echo "File is valid, and was successfully uploaded.\n";
	} else {
   		echo "Possible file upload attack!\n";
	}

	echo 'Here is some more debugging info:';
	print_r($_FILES);

	print "</pre>";
... help
 
change these lines:
Code:
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
           echo "File is valid, and was successfully uploaded.\n";
    } else {
           echo "Possible file upload attack!\n";
    }
to
Code:
$uploadfile = $uploaddir . basename($_FILES['fileupload']['name']);
if (move_uploaded_file($_FILES['fileupload']['tmp_name'], $uploadfile)) {
           echo "File is valid, and was successfully uploaded.\n";
    } else {
           echo "Possible file upload attack!\n";
    }
just copy and paste.

it looks to me that you have named your upload field "fileupload" and not "userfile" as the php.net script uses.

hth
Justin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top