使用php上传文档,pdf,jpg时出错

时间:2014-11-09 16:11:09

标签: php html pdo

请尝试使用php上传文档,.docx,.pdf,.jpg文件,但每次点击上传按钮时,都会收到以下消息:"不支持uploadedFile格式!上传&#34 ;.

请问问题出在哪里?它应该被上传'或'文件格式不受支持'。

感谢。

<?php
         require_once "include/db_handle.php";
    if (isset($_POST['upload'])) {
         if (!empty($_FILES['_file']['name'])) {
        if ($_FILES['_file']['type'] == 'application/msword') {
            $upload_folder = "./file_doc/";
            $pic_name = time() . ".doc";
            $pic_path = $upload_folder . $pic_name;
            move_uploaded_file($_FILES['_file']['tmp_name'], $pic_path);

            $upload = "INSERT INTO tfiles (name)  VALUES  ('$pic_name')";
            if ($db->query($upload)) {
            echo "uploaded";
            }   
        }
        if ($_FILES['_file']['type'] == 'application/vnd.openxmlformats-officedocument.wordprocessingml.document') {
            $upload_folder = "./file_doc/";
            $pic_name = time() . ".doc";
            $pic_path = $upload_folder . $pic_name;
            move_uploaded_file($_FILES['_file']['tmp_name'], $pic_path);

            $upload = "INSERT INTO tfiles (name)  VALUES  ('$pic_name')";
            if ($db->query($upload)) {
            echo "uploaded";
            }   
        }
        if ($_FILES['_file']['type'] == 'application/pdf') {
            $upload_folder = "./file_doc/";
            $pic_name = time() . ".pdf";
            $pic_path = $upload_folder . $pic_name;
            move_uploaded_file($_FILES['_file']['tmp_name'], $pic_path);

            $upload = "INSERT INTO tfiles (name)  VALUES  ('$pic_name')";
            if ($db->query($upload)) {
            echo "uploaded";
            }   
        }
        if ($_FILES['_file']['type'] == 'application/vnd.openxmlformats-officedocument.presentationml.presentation') {
            $upload_folder = "./file_doc/";
            $pic_name = time() . ".pptx";
            $pic_path = $upload_folder . $pic_name;
            move_uploaded_file($_FILES['_file']['tmp_name'], $pic_path);

            $upload = "INSERT INTO tfiles (name)  VALUES  ('$pic_name')";
            if ($db->query($upload)) {
            echo "uploaded";
            }   
        }

        if ($_FILES['_file']['type'] == 'image/jpeg') {
            $upload_folder = "./profile_pix/";
            $pic_name = time() . ".jpg";
            $pic_path = $upload_folder . $pic_name;
            require_once "include/resize.php";
            if (move_uploaded_file($_FILES['_file']['tmp_name'], $pic_path)) {
                $image = new Resize($pic_path);
                $image->resizeImage(180, 180, 'crop');
                $image->saveImage($pic_path);

                //thumbnail
                $image = new Resize($pic_path);
                $image->resizeImage(50, 50, 'crop');
                $image->saveImage($upload_folder . "thumb/" . $pic_name);
            }

            $upload = "INSERT INTO tfiles (name)  VALUES  ('$pic_name')";
            if ($db->query($upload)) {
            echo "uploaded";
            }   
        }

        else{
            echo "File format not supported!";        
            }
         }
    }
    ?>

HTML表单

  <p class="points" > Add Files</p>
     <form name="" action="" method="post" enctype="multipart/form-data">
          <input type="file" name= "_file" />
          <input type= "submit" name="upload" value="upload"/>
     </form>

0 个答案:

没有答案