ded Posted January 6, 2009 Share Posted January 6, 2009 I am giving a user the ability to replace a pdf files on the website at any given time. However, I want the pdf file to always be the same on the website since I have it linked on several pages. I also do not trust the user to always keep it the same name. How do I rename the file before uploading? index.php <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1"> <title></title> </head> <body> <div align="center"> Upload New Media Kit<br> <br> <form action="post.php" method="post" enctype="multipart/form-data"> <input name="filename" type="file" size="50"> <br><br> <input name="Submit" value="Submit Form" type="submit"> </form> </div> </body> </html> post.php <?php if($_FILES['filename']['error'] != 4) { $uploaddir = '../../pdfs/'; $uploadfile = $uploaddir . basename($_FILES['filename']['name']); echo '<pre>'; if (move_uploaded_file($_FILES['filename']['tmp_name'], $uploadfile)) { echo "File is valid, and was successfully uploaded.\n" . $uploadfile ; } else { echo "The file did not load properly. Please try again.\n" . $uploadfile; } print "</pre>"; } echo "<br>New Media Kit loaded to website"; ?> Link to comment https://forums.phpfreaks.com/topic/139711-solved-rename-uploaded-file/ Share on other sites More sharing options...
gevans Posted January 6, 2009 Share Posted January 6, 2009 $uploadfile = $uploaddir . basename($_FILES['filename']['name']); can be changed to $uploadfile = $uploaddir . 'anynameyouwant.pdf'; Link to comment https://forums.phpfreaks.com/topic/139711-solved-rename-uploaded-file/#findComment-730987 Share on other sites More sharing options...
bluesoul Posted January 6, 2009 Share Posted January 6, 2009 snip Link to comment https://forums.phpfreaks.com/topic/139711-solved-rename-uploaded-file/#findComment-730989 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.