我正在尝试使用上传图片,它在浏览器中运行完美,但它在iphone和ipad中不起作用。下面是iphone的代码和截图
test.php
---------
<?php
if(isset($_POST['submit']))
{
//echo "<pre>";
//print_r($_FILES);
//exit;
copy($_FILES["image1"]["tmp_name"],"upload/".$_FILES["image1"]["name"]);
copy($_FILES["image2"]["tmp_name"],"upload/".$_FILES["image2"]["name"]);
copy($_FILES["image3"]["tmp_name"],"upload/".$_FILES["image3"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["image1"]["name"];
echo "<br>";
echo "Stored in: " . "upload/" . $_FILES["image2"]["name"];
echo "<br>";
echo "Stored in: " . "upload/" . $_FILES["image3"]["name"];
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>demo</title>
</head>
<body>
<form method="post" enctype="multipart/form-data">
image 1 : <input type="file" name="image1" ><br/>
image 2 : <input type="file" name="image2" ><br/>
image 3 : <input type="file" name="image3" ><br/>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
从下面这个数组我们可以看到这个在iphone / ipad中显示的图像名称对所有人来说是相同的,当我尝试检查上传文件夹时,它只显示最后一张图像,即第三张图像。
[image1] => Array
(
[name] => image.jpg
[type] => image/jpeg
[tmp_name] => /tmp/phpewhdwx
[error] => 0
[size] => 44009
)
[image2] => Array
(
[name] => image.jpg
[type] => image/jpeg
[tmp_name] => /tmp/phpwYDYBM
[error] => 0
[size] => 27762
)
[image3] => Array
(
[name] => image.jpg
[type] => image/jpeg
[tmp_name] => /tmp/php0vqnB2
[error] => 0
[size] => 32961
)
答案 0 :(得分:5)
好的,我找到了解决办法:)
我们在ipad和iphone中有问题,因为他们使用所有图像的名称作为image.jpg所以如果我们使用多个图像,这将被覆盖,所以我们需要在复制时添加rand()或任何唯一的键名称文件夹中。
$image1 = rand().$_FILES["image1"]["name"];
$image2 = rand().$_FILES["image2"]["name"];
$image3 = rand().$_FILES["image3"]["name"];
copy($_FILES["image1"]["tmp_name"],"upload/".$image1);
copy($_FILES["image2"]["tmp_name"],"upload/".$image2);
copy($_FILES["image3"]["tmp_name"],"upload/".$image3);