dongqiuqiu4736 2016-10-27 09:55
浏览 32

在PHP一些pdf文件上传和其他没有

I'm trying to let users upload only pdf and image files, everything work fine but some pdf files can not be uploaded and others get uploaded very well. I tried to use multi pdf mimes like text/pdf, application/pdf and application/acrobat but the problem still occur.

here is my snippet

if ( isset( $_FILES['pdfFile2'] ) ) {
  $file2 = $_FILES['pdfFile2']['name'];
  $file_type2 = $_FILES['pdfFile2']['type'];
  $file_size2 = $_FILES['pdfFile2']['size'];
  if ($_FILES['pdfFile2']['type'] == "application/pdf" || $_FILES['pdfFile2']['type'] == "image/png" || $_FILES['pdfFile2']['type'] == "image/jpeg" || $_FILES['pdfFile2']['type'] == "image/gif" || $_FILES['pdfFile2']['type'] == "text/pdf" || $_FILES['pdfFile2']['type'] == "application/acrobat") {
    $source_file = $_FILES['pdfFile2']['tmp_name'];
    $dest_file = "uploads/".$_FILES['pdfFile2']['name'];

    if (file_exists($dest_file)) {
      print "The file name already exists!!";
    }
    else {
      move_uploaded_file( $source_file, $dest_file )
      or die ("Error!!");
       $sql="INSERT INTO upload(name,type,size, attach, user_id, term, year, content) VALUES('$file2','$file_type2','$file_size2', 'mshhd', $user_id, $term, '$year',$id)";
 mysqli_query($connection, $sql); 

      if($_FILES['pdfFile2']['error'] == 0) {
        print "Pdf file uploaded successfully!";
        print "<b><u>Details : </u></b><br/>";
        print "File Name : ".$_FILES['pdfFile2']['name']."<br.>"."<br/>";
        print "File Size : ".$_FILES['pdfFile2']['size']." bytes"."<br/>";
        print "File location : upload/".$_FILES['pdfFile']['name']."<br/>";
      }
    }
  }
  else {
    if ( $_FILES['pdfFile2']['type'] != "application/pdf") {
      print "Error occured while uploading file : ".$_FILES['pdfFile']['name']."<br/>";
      print "Invalid  file extension, should be pdf !!"."<br/>";
      print "Error Code : ".$_FILES['pdfFile2']['error']."<br/>";
    }
  }
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
    • ¥20 软件测试决策法疑问求解答
    • ¥15 win11 23H2删除推荐的项目,支持注册表等
    • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
    • ¥15 qt6.6.3 基于百度云的语音识别 不会改
    • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
    • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
    • ¥15 lingo18勾选global solver求解使用的算法
    • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
    • ¥20 测距传感器数据手册i2c