[Solved] Error With Simple Upload File Form

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
User avatar
bironeb
Forum Commoner
Posts: 59
Joined: Thu Nov 20, 2003 12:02 pm

[Solved] Error With Simple Upload File Form

Post 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?
Last edited by bironeb on Wed Mar 17, 2004 5:36 pm, edited 1 time in total.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post 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.
User avatar
bironeb
Forum Commoner
Posts: 59
Joined: Thu Nov 20, 2003 12:02 pm

Post by bironeb »

Thanks Markl999 you've done it again! That works great! How can I repay you? :D
Post Reply