我之前已经制作过几次上传图像,但我从未遇到任何问题。我只是复制脚本,它工作正常,但在我复制后,我不知道为什么它保持显示我没有使用正确的扩展。你能发现错误吗?
这是表单脚本:
<tr height="30">
<td> </td>
<td align="right">Gambar Barang </td>
<td><input type="file" name="gambar" /></td>
</tr>
及其行动,
$errors= array();
$uploaddir = 'images/';
$uploadfile = $uploaddir . basename($_FILES['gambar']['name']);
$gambar = $_FILES['gambar']['name'];
$gambar_size = $_FILES['gambar']['size'];
$gambar_type = $_FILES['gambar']['type'];
$gambar_tmp = $_FILES['gambar']['tmp_name'];
$gambar_ext=strtolower(end(explode('.',$_FILES['gambar']['name'])));
$expensions= array("jpeg","jpg","png");
if(in_array($gambar_ext,$expensions)=== false){
$errors[]="extension not allowed, please choose a JPEG or PNG file.";
}
if($gambar_size > 4097152){
$errors[]='File size must be excately 4 MB';
}
if(empty($errors)==true){
copy($_FILES['gambar']['tmp_name'], $uploadfile);
}else{
print_r($errors);
}
答案 0 :(得分:2)
有几件事可能导致文件上传失败:
答案 1 :(得分:1)
您的代码运行正常,只需确保您的表单使用:
方法= 'POST'
和(正如Reto已经提到的那样) - enctype =“multipart / form-data”
即。类似的东西:
R