jandrews3 Posted September 18, 2008 Share Posted September 18, 2008 I'm having difficulty with an upload script. I want the script to upload the file and save it in the "documents" folder using the actual name of the file. I can get it to work ONLY IF I place a VALUE="<?print $version?>" in the form (given that the variable $version is pre-assigned). Otherwise no value gets passed with $version. I provided 2 chunks of code: the upload script and then the handler. THANKS! <form action="uploader_b.php" method="post" enctype="multipart/form-data" style="margin-bottom: 0;"> <input type="file" name="file"> <input type="hidden" name="version"> <input type="submit" value="Upload File"> </form> and if ($file_name !="") { if ($photo != ""){$file_name = $version.".pdf";} else {$file_name = $version.".pdf";} copy ("$file", "documents/$file_name") or die("Could not copy file"); } else { die("No file specified"); } $filename = $file_name; print $file_name."<br>"; print $version."<br>"; print $file."<br>"; Quote Link to comment Share on other sites More sharing options...
F1Fan Posted September 18, 2008 Share Posted September 18, 2008 use the $_FILE variable, like this: <?php $filename = $_FILES["file"]["name"]; ?> Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted September 18, 2008 Share Posted September 18, 2008 More info on the $_FILES superglobal point out by F1Fan here... http://us3.php.net/features.file-upload Quote Link to comment Share on other sites More sharing options...
jandrews3 Posted September 18, 2008 Author Share Posted September 18, 2008 Thanks, F1! I don't know why it worked, but it did! Thanks also to GENERIC. I'll read the link. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.