I need to upload several images, I have 2 problems, the first one that does not allow me to upload 2 or more files when it is from the cell phone (here something important, if it is from the cell phone you must open the camera and if it is in PC it must show the window of file selection, this works fine, but with the cell phone it only leaves one, so far I have only tried it on Android using Crhome) and the second detail is with the first element is not saved and if it is just a file because it does not either, it seems that it does not take position [0], when I put more than one image, the first does not save and the others are saved correctly. I've been trying for a while and I do not see the problem. Annex the structure of my files: \camera
└───uploads
└───index.php
└───upload.php
index.php :
<html>
<head>
<meta charset="UTF-8">
<title>upload</title>
</head>
<body>
<form action="upload.php" method="post" multipart="" enctype="multipart/form-data">
<input type="file" name="img[]" accept="image/*" id="capture" capture="camera" multiple >
<input type="submit">
</form>
</body>
</html>
And upload.php :
<?php
echo '<pre>';
$img = $_FILES['img'];
if(!empty($img))
{
$img_desc = reArrayFiles($img);
print_r($img_desc);
foreach($img_desc as $val)
{
$newname = date('YmdHis',time()).mt_rand().'.jpg';
move_uploaded_file($val['tmp_name'],'./uploads/'.$newname);
}
}
function reArrayFiles($file)
{
$file_ary = array();
$file_count = count($file['name']);
$file_key = array_keys($file);
for($i=0;$i<$file_count;$i++)
{
foreach($file_key as $val)
{
$file_ary[$i][$val] = $file[$val][$i];
}
}
return $file_ary;
}
?>
Aucun commentaire:
Enregistrer un commentaire