我刚从asp转到php,我能够将文件上传到服务器。现在我想要做的是在上传完成之前重命名文件,并回显新命名的文件
<?php
if(isset($_FILES['image'])){
$errors= array();
$file_name = $_FILES['image']['name'];
$file_size =$_FILES['image']['size'];
$file_tmp =$_FILES['image']['tmp_name'];
$file_type=$_FILES['image']['type'];
$file_ext=strtolower(end(explode('.',$_FILES['image']['name'])));
$expensions= array("jpeg","jpg","png");
if(in_array($file_ext,$expensions)=== false){
$errors[]="extension not allowed, please choose a JPEG or PNG file.";
}
if($file_size > 2097152){
$errors[]='File size must be excately 2 MB';
}
if(empty($errors)==true){
move_uploaded_file($file_tmp,"../complains_photos/".$file_name);
echo $file_type;
}else{
print_r($errors);
}
}
?>
<html>
<body>
<form action="" method="POST" enctype="multipart/form-data">
<input type="file" name="image" />
<input type="submit"/>
</form>
</body>
</html>
答案 0 :(得分:1)
只需更改要传递给move_uploaded_file函数的名称即可。像这样:
geocodeAddressString(2)
geocodeAddressString(5)
geocodeAddressString(1)
geocodeAddressString(3)
geocodeAddressString(4)
同时更改回显以发送$ destinationFileName
答案 1 :(得分:0)
按以下方式更改$destinationFileName = date('Ymd').'.'.$file_ext;
move_uploaded_file($file_tmp,"../complains_photos/".$destinationFileName);
语句,
move_uploaded_file(...);
您可以根据自己的喜好更改日期格式。