dongzai3917 2017-09-19 19:57
浏览 25
已采纳

用PHP上传文件问题

I have made an upload image a couple times before and I never have problems. And I just copy the script and it worked fine, but after I copy I don't know why it keep shows that I'm not using the right extension. Can you spot the mistake?

This is the form script:

<tr height="30">
        <td>&nbsp;</td>
        <td align="right">Gambar Barang &nbsp;&nbsp;&nbsp;</td>
        <td><input type="file" name="gambar" /></td>
</tr>

and its the action,

$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);
  }
  • 写回答

2条回答 默认 最新

  • douhong4452 2017-09-19 20:03
    关注

    There are several things that could cause file upload to fail:

    • does the upload form have enctype="multipart/form-data"?
    • is file_uploads = On in php.ini?
    • what is the max post/upload limit in php.ini?
    • did you check the permissions for the upload folder?
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大