mas_ Posted July 8, 2010 Share Posted July 8, 2010 I am trying to upload a file to the server, but the problem that when I open upload.php and click on submit I get a message saying "no file chosen" !! I need help with my code below <html> <head> <title>Upload</title> </head> <body> <?php if($File){ print ("File name: $File_name<P>\n"); print ("File size: $File_size<P>\n"); if (copy ($File, "users/$File_name")) { print ("Your file was successfully uploaded!<P>\n"); } else { print ("Your file could not be copied.<P>\n"); } unlink ($File); } print ("Upload a file:\n"); print ("<FORM ACTION=\"upload.php\" METHOD=POST ENCTYPE=\"multipart/form-data\">\n"); print ("File <INPUT TYPE=FILE NAME=\"File\" SIZE=20><BR>\n"); print ("<INPUT TYPE=SUBMIT NAME=\"SUBMIT\" VALUE=\"Submit\"></FORM>\n"); ?> </BODY> </HTML> Link to comment https://forums.phpfreaks.com/topic/207084-uploading-a-file-to-server/ Share on other sites More sharing options...
kenrbnsn Posted July 8, 2010 Share Posted July 8, 2010 You are assuming that register_globals are enabled, which hasn't been the case in over 6 years. And your code is wrong. Here's your code re-written to work: <html> <head> <title>Upload</title> </head> <body> <?php if(isset($_FILES['File'])){ echo "File name: {$_FILES['File']['name']}<P>\n"; echo "File size: {$_FILES['File']['size']}<P>\n"; if (move_uploaded_file ($_FILES['File']['tmp_name'], "users/{$_FILES['File']['name']}")) { print ("Your file was successfully uploaded!<P>\n"); } else { print ("Your file could not be copied.<P>\n"); } } echo "Upload a file:\n"; echo "<form action='' method='POST' enctype='multipart/form-data'>\n"; echo "File <input type='file' name='File' size='20'><BR>\n"; echo "<input type='submit' name='submit' value='Submit'></form>\n"; ?> </body> </html> Ken Link to comment https://forums.phpfreaks.com/topic/207084-uploading-a-file-to-server/#findComment-1082822 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.