php将文件上传到服务器并重命名

时间:2016-08-23
php上传文件到服务器是WEB开发中经常会遇到的需求模块,本文章向大家分享将文件上传到服务器并重命名的php源码,需要的朋友可以参考一下。

html表单代码如下所示:

<form action="<?php print $PHP_SELF?>" enctype="multipart/form-data" method="post">
   Last Name:<br /> <input type="text" name="name" value="" /><br />
   Class Notes:<br /> <input type="file" name="classnotes" value="" /><br />
   <p><input type="submit" name="submit" value="Submit Notes" /></p>
</form>

 

php上传文件及重命名文件代码如下:

<?php
   define ("FILEREPOSITORY","./");

   if (is_uploaded_file($_FILES['classnotes']['tmp_name'])) {

      if ($_FILES['classnotes']['type'] != "application/pdf") {
         echo "<p>Class notes must be uploaded in PDF format.</p>";
      } else {
         /* http://www.manongjc.com/article/1391.html */
         $name = $_POST['name'];
         $result = move_uploaded_file($_FILES['classnotes']['tmp_name'], FILEREPOSITORY."/$name.pdf");
         if ($result == 1) echo "<p>File successfully uploaded.</p>";
         else echo "<p>There was a problem uploading the file.</p>";
      } #endIF
   } #endIF
?>

上一页 下一页

原文地址:http://www.manongjc.com/article/1390.html