• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 857
  • Last Modified:

Upload problem with pdf

Hi, with help from EE I am just about done my upload file. The only problem left is that when I try to upload a PDF I get the Invalid File response from the script below. Could someone share with me what I have wrong here? Thanks in advance.
<?php
if ((($_FILES["file"]["type"] == "application/pdf")
|| ($_FILES["file"]["type"] == "application/msword")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 20000000))
  {
  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";
  }
?>

Open in new window

0
pertrai1
Asked:
pertrai1
  • 3
  • 2
1 Solution
 
BenMorelCommented:
hi, can you please put this line in the top of your php file, then upload the pdf file, then put the result back here ?
Thanks !
Ben
<?php
print_r($_FILES);
die;
?>

Open in new window

0
 
pertrai1Author Commented:
Array ( [file] => Array ( [name] => scpahaentryform.pdf [type] => application/pdf [tmp_name] => /tmp/phpAY9fFF [error] => 0 [size] => 50237 ) )
0
 
BenMorelCommented:
Should work ...
if ((($_FILES["file"]["type"] == "application/pdf")
|| ($_FILES["file"]["type"] == "application/msword")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 20000000))
passes without problem with your $_FILES !
0
 
BenMorelCommented:
Did you try again ?
0
 
pertrai1Author Commented:
Ben, I had it a little wrong with my database. I thank you for taking the time.
0

Featured Post

[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now