所以我有一个表单被发送到同一页面内的一个函数。现在单个文件上传工作。但是,当涉及到上传多个文件时,它会开始出错。我试着谷歌搜索它,但在搜索前3个结果页面的方式都是读取和noc结果。
所以我的表格:
if(isset($_POST['btn-send'])){
$foto = $_FILES['image'];
$img_ff = 'image'; // Form name of the image
$dst_img = strtolower($_FILES[$img_ff]['name']); // This name will be given to the image. (in this case: lowercased original image name uploaded by user).
$dst_path = '../images/project/' ; // The path where the image will be moved to.
$overig->uploadimage($img_ff, $dst_path, $dst_img);
}
?>
<form enctype="multipart/form-data" class="w3-container" style="background-color: white;" action="" method="post">
<div class="w3-row-padding">
<div class="w3-half">
<div class="w3-group">
<label class="w3-label w3-text-teal"><b>Selecteer Foto(s)</b></label>
<input class="w3-input" type="file" id="image" name="image[]" multiple="multiple">
</div>
</div>
<div class="w3-half">
<div class="w3-group">
<label class="w3-label w3-text-teal"><b>Toevoegen</b></label>
<input type="submit" value="Voeg dit project toe" name="btn-send" class="w3-btn w3-blue-grey">
</div>
</div>
</div>
</form>
和我的功能页面,其结果也是
public function uploadimage($img_ff, $dst_path, $dst_img){
$dst_cpl = $dst_path . "/". basename($dst_img);
$dst_name = preg_replace('/\.[^.]*$/', '', $dst_img);
$dst_ext = strtolower(end(explode(".", $dst_img)));
while(file_exists($dst_cpl) == true){
$i = $i+1;
$dst_img = $dst_name . $i . '.' . $dst_ext;
$dst_cpl = $dst_path . basename($dst_img);
}
move_uploaded_file($_FILES[$img_ff]['tmp_name'], $dst_cpl);
$dst_type = exif_imagetype($dst_cpl);
if(( (($dst_ext =="jpg") && ($dst_type =="2")) || (($dst_ext =="jpeg") && ($dst_type =="2")) || (($dst_ext =="gif") && ($dst_type =="1")) || (($dst_ext =="png") && ($dst_type =="3") )) == false){
unlink($dst_cpl);
die('<p>The file "'. $dst_img . '" with the extension "' . $dst_ext . '" and the imagetype "' . $dst_type . '" is not a valid image. Please upload an image with the extension JPG, JPEG, PNG or GIF and has a valid image filetype.</p>');
}
}
每次我得到的错误都是:
文件&#34; 1。&#34;扩展名&#34;&#34;和图像类型&#34;&#34;不是有效的图像。请上传带有JPG,JPEG,PNG或GIF扩展名的图片,并使用有效的图片文件类型。
有人可以帮帮我吗?
Vardump在foreach之前
array(5) {
["name"]=>
array(1) {
[0]=>
string(10) "socket.jpg"
}
["type"]=>
array(1) {
[0]=>
string(10) "image/jpeg"
}
["tmp_name"]=>
array(1) {
[0]=>
string(14) "/tmp/phpQIXgAp"
}
["error"]=>
array(1) {
[0]=>
int(0)
}
["size"]=>
array(1) {
[0]=>
int(146543)
}
}
在foreach之后vardump
array(1) {
[0]=>
string(10) "socket.jpg"
}