我试过应用程序/ pdf ....如何上传PDF文件?

'<?php
    $allowedExts = array("jpg", "jpeg", "gif", "png");
$extension = end(explode(".", $_FILES["file"]["name"]));
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 20000)
&& in_array($extension, $allowedExts))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br>";
    echo "Type: " . $_FILES["file"]["type"] . "<br>";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";

    if (file_exists("upload/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "upload/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
      }
    }
  }
else
  {
  echo "Invalid file";
  }
?> '

我试过应用程序/ pdf ....如何上传PDF文件? 我可以得到JPG和PNG上传到我的网站,但我不能为DOC,TXT和PDF。 我知道这个代码是用于$ allowedExts = array(“jpg”,“jpeg”,“gif”,“png”); 只有,但如何改变|| ($ _FILES [“file”] [“type”] ==“image / jpeg”)为|| ($ _FILES [“file”] [“type”] ==“application / pdf”)? Thanx提前...


您的代码正在寻找扩展(pdf)&&类型

PDF格式的MIME类型:

application / pdf,application / x-pdf,application / acrobat,applications / vnd.pdf,text / pdf,text / x-pdf

Microsoft文档的扩展和MIME类型:http://filext.com/faq/office_mime_types.php


我认为你可以解决这个问题:

修改你的页面添加这一行

echo "Type: " . $_FILES["file"]["type"] . "<br> Extension: " . $_FILES["file"]["name"] . "<br>";

它将显示文件类型和名称。

链接地址: http://www.djcxy.com/p/46681.html

上一篇: I've tried application/pdf....How to upload pdfs?

下一篇: PHP image upload security check list