Php 如何上传img[]并在保存时重命名?
我用学校的例子 1) 当我添加img时,我如何重命名,因为我想用我想重命名的相同名称添加相同的图像 2) 如果我的Php 如何上传img[]并在保存时重命名?,php,Php,我用学校的例子 1) 当我添加img时,我如何重命名,因为我想用我想重命名的相同名称添加相同的图像 2) 如果我的fileToupload[]如何上传使用for(I=0,I
fileToupload[]
如何上传使用for(I=0,I<?,I++)
我应该使用计数($\u文件)
这是我的代码:
$target_dir = "../../_files/images/source/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
$filename = md5($_FILES['fileToUpload']['tmp_name']);
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
var_dump($_FILES["fileToUpload"]["tmp_name"], $target_file);
} else {
echo "Sorry, there was an error uploading your file.";
}
}
只要每次更新$target_文件的值,它就会自动重命名图像名称。您可以阅读此堆栈回答@iCoders谢谢sir希望该链接能帮助您解决问题谢谢它现在可以工作=]@iCoderscan您能给我举个例子吗?请