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 孟德尔随机化结果不一致
  • ¥15 深度学习残差模块模型
  • ¥50 怎么判断同步时序逻辑电路和异步时序逻辑电路
  • ¥15 差动电流二次谐波的含量Matlab计算
  • ¥15 Can/caned 总线错误问题,错误显示控制器要发1,结果总线检测到0
  • ¥15 C#如何调用串口数据
  • ¥15 MATLAB与单片机串口通信
  • ¥15 L76k模块的GPS的使用
  • ¥15 请帮我看一看数电项目如何设计
  • ¥23 (标签-bug|关键词-密码错误加密)