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
bironeb
Forum Commoner
Posts: 59 Joined: Thu Nov 20, 2003 12:02 pm
Post
by bironeb » Wed Mar 17, 2004 5:23 pm
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їimg1] != ""){
@copy($_FILESїimg1]їtmp_name],
"/Apache/htdocs/temp/".$_FILESїimg1]їname])
or die("Couldn't copy the file.");
}else{
die("No input file specified");
}
?>
<html>
<head>
<title>Successful File Upload</title>
</head>
<body>
<h1>Success!</h1>
<p>You sent: <?echo $_FILESїimg1]їname]; ?>, a <? echo
$_FILESїimg1]їsize]; ?> byte file with a mime type of <? echo
$_FILESїimg1]ї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.
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Wed Mar 17, 2004 5:27 pm
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.
bironeb
Forum Commoner
Posts: 59 Joined: Thu Nov 20, 2003 12:02 pm
Post
by bironeb » Wed Mar 17, 2004 5:32 pm
Thanks Markl999 you've done it again! That works great! How can I repay you?