Jump to content

[SOLVED] Rename Uploaded File


ded

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.