上传重命名文件 [英] Upload file with renaming

查看:86
本文介绍了上传重命名文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨有没有办法可以将我的脚本更改为在存储时自动命名文件?也许数字可以说我每次上传图片时都应该将它重命名为前一个数字后的数字。



例如

上传1:1.jpg

上传2:2.jpg等..



我现有的代码如下



Form.html



Hi Is there a way I can change my script to auto name the file when its being stored? Maybe by numbers lets say each time I upload a picture it should rename it to the number after the previous number.

like example"
Upload 1: 1.jpg
Upload 2: 2.jpg etc..

My current code I have is as follow

Form.html

<html>
<body><br>
<h1>My upload file form.</h1>


<form enctype="multipart/form-data" action="process.php" method="post">


Enter File Name:<input type="text" name="name" value="Please enter file name:" /><br>


Enter Description:<input type="text" name="desc" value="Description:" /><br>


Select image:<input type="file" name="prodImg"><br>


<input type="submit" value="Submit Page" />


</form>
<?php





和我的处理脚本



process.php





And my processing script

process.php

<?php


extract($_POST);


$name;


$desc;


$fileType = $_FILES['prodImg']['type'];
 $fileSize = $_FILES['prodImg']['size'];


if($fileSize/1024 > '150') {
 echo 'Filesize is not correct it should equal to 2 MB or less than 2 MB.';
 exit();
 } //FileSize Checking


if($fileType != 'image/gif' &&
 $fileType != 'image/jpg' &&
 $fileType != 'image/jpeg'


 )     {
 echo 'Sorry this file type is not supported we accept only. Jpeg, Gif, PNG, or ';
 exit();
 } //file type checking ends here.
 $upFile = 'files/galaxywars/'.date('Y_m_d_H_i_s').$_FILES['prodImg']['name'];


if(is_uploaded_file($_FILES['prodImg']['tmp_name'])) {
 if(!move_uploaded_file($_FILES['prodImg']['tmp_name'], $upFile)) {
 echo 'Problem could not move file to destination. Please check again later. <a href="index.php">Please go back.</a>';
 exit;
 }
 } else {
 echo 'Problem: Possible file upload attack. Filename: ';
 echo $_FILES['prodImg']['name'];
 exit;
 }
 $prodImg = $upFile;
  //File upload ends here.


$upFile;
echo "Thank you for sending your file";


 ?>
<?php






include "menu3.php";


?>





任何人都可以帮助我...



Can anybody assist me please...

推荐答案

_POST);


_POST);


name ;


name;


desc ;


desc;


这篇关于上传重命名文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆