#1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Apr 2001
    Posts
    910
    Rep Power
    0

    Why am I getting invalid file with upload


    I am using the below code for uploading, at one time it was working but now I am getting the invalid file error why?

    Tim
    PHP Code:
    $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/jpg")
    || (
    $_FILES["file"]["type"] == "image/png")
    || (
    $_FILES["file"]["type"] == "image/pjpeg"))
    && (
    $_FILES["file"]["size"] < 2000000000000000)
    && 
    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"],
          
    "/home/content/37/8696437/html/know/beta/test/anew/upload/" $_FILES["file"]["name"]);
          echo 
    "Stored in: " "/home/content/37/8696437/html/know/beta/test/anew/upload/" $_FILES["file"]["name"];

    }

    else
      {
      echo 
    "Invalid file test";
      } 
    Last edited by timsharpe; October 11th, 2012 at 09:28 AM.
    Daily Deals from Kingston to Brockville and Cornwall Ontario. www.seawaydeals.com
  2. #2
  3. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6351
    "Invalid file" doesn't appear in your code.

    If you're getting some random error, google for it to see what could be causing it. Or debug your code.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Apr 2001
    Posts
    910
    Rep Power
    0
    Sorry added the end of the code I have searched and cannot find out why
    Daily Deals from Kingston to Brockville and Cornwall Ontario. www.seawaydeals.com
  6. #4
  7. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6351
    Ok, that's the ELSE of a very large IF

    Print out the results of all the various things you check in the IF. See why it's failing.

    This is very basic debugging. I can't fix it by staring at it, and neither can you. Check what's happening.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,464
    Rep Power
    594
    Since that else goes with your first 'if', obviously one of the conditions is not being met. So it has nothing to do with file upload. You need to echo all those variables used in that 'if' to see which one is causing it to be false, then figure out why.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  10. #6
  11. No Profile Picture
    I haz teh codez!
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2003
    Posts
    2,549
    Rep Power
    2337
    Originally Posted by ManiacDan
    Ok, that's the ELSE of a very large IF

    Print out the results of all the various things you check in the IF. See why it's failing.

    This is very basic debugging. I can't fix it by staring at it, and neither can you. Check what's happening.
    Join Date: Apr 2001
    Posts: 906

    I ♥ ManiacDan & requinix

    This is a sig, and not necessarily a comment on the OP:
    Please don't be a help vampire!
  12. #7
  13. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6351
    I saw. Believe me, I saw.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

IMN logo majestic logo threadwatch logo seochat tools logo