Page 1 of 1

[Solved] Error With Simple Upload File Form

Posted: Wed Mar 17, 2004 5:23 pm
by bironeb
Below is my simple code:

Code: Select all

<html>
<head>
<title>Upload a File</title>
</head>
<body>
<h1>Upload a File</h1>
<Form METHOD="POST" ACTION=" do_upload.php" ENCTYPE="multipart/form-data">
<p><strong>File to Upload:</strong><br>
<INPUT TYPE="file" NAME="img1" SIZE="30"></p>
<p><INPUT TYPE="submit" NAME="submit" VALUE="Upload File"></p>
</form>
</body>
</html>
and the php file

Code: Select all

<?
if ($_FILES&#1111;img1] != "")&#123;
	@copy($_FILES&#1111;img1]&#1111;tmp_name],
	"/Apache/htdocs/temp/".$_FILES&#1111;img1]&#1111;name])
	or die("Couldn't copy the file.");
&#125;else&#123;
	die("No input file specified");
&#125;
?>
<html>
<head>
<title>Successful File Upload</title>
</head>
<body>
<h1>Success!</h1>
<p>You sent: <?echo $_FILES&#1111;img1]&#1111;name]; ?>, a <? echo 
$_FILES&#1111;img1]&#1111;size]; ?> byte file with a mime type of <? echo
$_FILES&#1111;img1]&#1111;type]; ?>.</p>
</body>
</html>
When I open the html page and choose a file to upload and submit it loads the php page with the following error.

Notice: Use of undefined constant img1 - assumed 'img1' on line 2
Couldn't copy the file.

any ideas?

Posted: Wed Mar 17, 2004 5:27 pm
by markl999
Use of undefined constant img1 - assumed 'img1' on line 2
It means you should be using $_FILES['img1']['name'] , same goes for the other places where you don't quote array elements.

Also, instead of if ($_FILES[img1] != ""){ ... if(!empty($_FILES)){ would be better imho.

Posted: Wed Mar 17, 2004 5:32 pm
by bironeb
Thanks Markl999 you've done it again! That works great! How can I repay you? :D