PHP Upload form,PDF,Doc& DOCX [英] PHP Upload form, PDF, Doc & Docx

查看:134
本文介绍了PHP Upload form,PDF,Doc& DOCX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



I'm struggling to make this upload code work for a docx file, it works okay for doc and pdf..

$allowedExts = array("pdf", "doc", "docx");
$extension = end(explode(".", $_FILES["file"]["name"]));
if ((($_FILES["file"]["type"] == "application/pdf")
|| ($_FILES["file"]["type"] == "application/msword"))
&& ($_FILES["file"]["size"] < 20000000)
&& in_array($extension, $allowedExts))
 {
  if ($_FILES["file"]["error"] > 0)
 {
   echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
 }

我努力使这个上传代码适用于docx文件, > $ allowedExts = array(pdf,doc,docx);
$ extension = end(explode(。,$ _FILES [file] [name]));
if((($ _FILES [file] [type] ==application / pdf)
||($ _FILES [file] [type] ==应用程序/ msword))
&&($ _FILES [file] [size]< 20000000)
&& in_array($ extension,$ allowedExts))
{
if($ _FILES [file] [error]> 0)
{
echo返回代码:。 $ _FILES [file] [error]。 <峰; br> 中;
}

this is part of a project from a while ago and i honestly can't remember how to do it..

这是前一个项目的一部分,我真的不能请记住如何做到这一点。

I know it's not the most secure upload method, but if someone could help it would be appreciated!

我知道这不是最安全的上传方式,但如果有人可以帮助它,将不胜感激!

I'm thinking i need to add another line here:

我想我需要在这里添加另一行:

if ((($_FILES["file"]["type"] == "application/pdf") || ($_FILES["file"]["type"] == "application/msword")) && ($_FILES["file"]["size"] < 20000000)

Just not sure what.. Help is appreciated!

Just不知道是什么..帮助表示赞赏!

So i've got to this stage (with the help of comments!)

编辑:
所以我已经到了这个阶段(在评论的帮助下!)

$allowedExts = array("pdf", "doc", "docx"); $extension = end(explode(".", $_FILES["file"]["name"])); //if ((($_FILES["file"]["type"] == "application/pdf") //|| ($_FILES["file"]["type"] == "application/msword")) if (($_FILES["file"]["type"] == "application/pdf") || ($_FILES["file"]["type"] == "application/msword") || ($_FILES["file"]["type"] == "application/vnd.openxmlformats- officedocument.wordprocessingml.document")) && ($_FILES["file"]["size"] < 20000000) && in_array($extension, $allowedExts)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br>"; } else {

But now its coming up with: Parse error: syntax error, unexpected T_BOOLEAN_AND in /var/sites/s/stanation.com/public_html/forms/process/insert.php on line 30

但现在它的出现:解析错误:语法错误,意想不到的T_BOOLEAN_AND在/var/sites/s/stanation.com/public_html/forms/process/insert.php上,第30行

解决方案

推荐答案

application/vnd.openxmlformats-officedocument.wordprocessingml.document

编辑:

这是代码。您缺少括号

<?php

    $allowedExts = array("pdf", "doc", "docx");
    $extension = end(explode(".", $_FILES["file"]["name"]));
    if (($_FILES["file"]["type"] == "application/pdf") || ($_FILES["file"]["type"] == "application/msword") || ($_FILES["file"]["type"] == "application/vnd.openxmlformats-officedocument.wordprocessingml.document") && ($_FILES["file"]["size"] < 20000000) && in_array($extension, $allowedExts))
    {
      if ($_FILES["file"]["error"] > 0)
      {
         echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
      }
      else
      {
        echo "Success";
      }
  }

这篇关于PHP Upload form,PDF,Doc&amp; DOCX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆