The simplest Upload problem

I have been trying for quite some time but it seems that no matter how I try, I could not upload ANY files.


<form enctype="multipart/form-data" action="simpledeal.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Send this file: <input name="userfile" type="file" />
<input type="submit" value="Send File" />


<?php if (is_uploaded_file($_FILES['userfile']['tmp_name'])) { echo "File ". $_FILES['userfile']['name'] ." uploaded successfully."; echo "Displaying contentsn"; readfile($_FILES['userfile']['tmp_name']); } else { echo "Possible file upload attack: "; echo "filename '". $_FILES['userfile']['tmp_name'] . "."; } ?>

Thanks! Let me know what information do I need to give…

As far as I can tell you don’t have any code to actually copy the file to the server.

Something like:

$tempname1 = $_FILES[‘photo1’][‘tmp_name’];
$filetype1= $_FILES[‘photo1’][‘type’];
$filename1 = $_FILES[‘photo1’][‘name’];

//Checking to make sure the fields aren't empty
	copy($tempname1, $path.$filename1) or die("Couldn't copy the file!");
	echo "1st File Uploaded Successfully!";


Hey, thanks for your help. But I don’t think it’s a code issue cause many codes I tried are taken from websites.

Ha. But all of a sudden things finally got working without me understanding why. It just worked. I suspect it’s a configuration issue.

Anyway this is a code snippet for those who wanna test out their system.

$uploaddir = ‘/apache2/files/’;
$uploadfile = $uploaddir . basename($_FILES[‘userfile’][‘name’]);

echo $uploadfile;
echo '<br>';
echo $_FILES['userfile']['tmp_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 "</pre>";

Those two code snippets don’t match. The latter one contains move_uploaded_file(), which basically comes down to the copy() function Ragster provided, and is necessary to create a permanent file from the temporarily uploaded file.

Sponsor our Newsletter | Privacy Policy | Terms of Service