首先,我对SO,HTML& PHP,也是英语不是我的主要语言,如果我以任何方式冒犯你或只是提出愚蠢的问题,那就很抱歉。
我有一个(几乎)全功能的上传功能。上传照片的方式各不相同,除非我直接用手机拍照。
我有三星Galaxy S2。 (它似乎在iPhone上运行,尚未在其他手机上测试过)
我的表格:
<form action='m.dier_plaatsen.php' method='post' enctype='multipart/form-data'>
<table>
<tr>
<td>
Kies een bestand:
</td>
<td>
<input type='file' name='img1' value='Choose file' />
</td>
</tr>
<tr>
<td>
Kies een bestand:
</td>
<td>
<input type='file' name='img2' value='Choose file' />
</td>
</tr>
<tr>
<td>
Kies een bestand:
</td>
<td>
<input type='file' name='img3' value='Choose file' />
</td>
</tr>
</table>
<input type='submit' class='button_styled' value='Previous' name='prev7' />
<input class='button_styled' name='next7' type='submit' value='Next' />
</form>
我的上传脚本:
if(isset($_FILES['img1'])){
$img1_file_name = $_FILES['img1']['name'];
$img1_file_ext = strtolower(end(explode('.',$img1_file_name)));
$img1_file_size = $_FILES['img1']['size'];
$img1_file_tmp = $_FILES['img1']['tmp_name'];
if($img1_file_ext !== ""){
$file_chosen = true;
$img1_set = true;
if(in_array($img1_file_ext, $allowed_ext) === false){
$errors[] = "Extension not allowed";
}
}
if($img1_file_size > 1048576){
$errors[] = "File size must be under 1MB";
}
}
if(isset($_FILES['img2'])){
$img2_file_name = $_FILES['img2']['name'];
$img2_file_ext = strtolower(end(explode('.',$img2_file_name)));
$img2_file_size = $_FILES['img2']['size'];
$img2_file_tmp = $_FILES['img2']['tmp_name'];
if($img2_file_ext !== ""){
$file_chosen = true;
$img2_set = true;
if(in_array($img2_file_ext, $allowed_ext) === false){
$errors[] = "Extension not allowed";
}
}
if($img2_file_size > 1048576){
$errors[] = "File size must be under 1MB";
}
}
if(isset($_FILES['img3'])){
$img3_file_name = $_FILES['img3']['name'];
$img3_file_ext = strtolower(end(explode('.',$img3_file_name)));
$img3_file_size = $_FILES['img3']['size'];
$img3_file_tmp = $_FILES['img3']['tmp_name'];
if($img3_file_ext !== ""){
$file_chosen = true;
$img3_set = true;
if(in_array($img3_file_ext, $allowed_ext) === false){
$errors[] = "Extension not allowed";
}
}
if($img3_file_size > 1048576){
$errors[] = "File size must be under 1MB";
}
}
if(!$file_chosen){
$errors[] = "No file has been chosen";
}
if(empty($errors)){
$tmp_random1 = rand().".".$img1_file_ext;
$tmp_random2 = rand().".".$img2_file_ext;
$tmp_random3 = rand().".".$img3_file_ext;
while(file_exists("tmp/".$tmp_random1)){
$tmp_random1 = rand().".".$img1_file_ext;
}
while(file_exists("tmp/".$tmp_random1)){
$tmp_random2 = rand().".".$img2_file_ext;
}
while(file_exists("tmp/".$tmp_random1)){
$tmp_random3 = rand().".".$img3_file_ext;
}
if($img1_set){
move_uploaded_file($img1_file_tmp, 'tmp/'.$tmp_random1);
$_SESSION['tmp_random1'] = $tmp_random1;
}
if($img2_set){
move_uploaded_file($img2_file_tmp, 'tmp/'.$tmp_random2);
$_SESSION['tmp_random2'] = $tmp_random1;
}
if($img3_set){
move_uploaded_file($img3_file_tmp, 'tmp/'.$tmp_random3);
$_SESSION['tmp_random3'] = $tmp_random1;
}
}
有什么想法吗?