The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
Why am I getting invalid file with upload
Discuss Why am I getting invalid file with upload in the PHP Development forum on Dev Shed. Why am I getting invalid file with upload PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

October 11th, 2012, 08:41 AM
|
|
Contributing User
|
|
Join Date: Apr 2001
Posts: 909
Time spent in forums: 5 Days 5 h 34 m 32 sec
Reputation 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";
}
__________________
Daily Deals from Kingston to Brockville and Cornwall Ontario. www.seawaydeals.com
Last edited by timsharpe : October 11th, 2012 at 09:28 AM.
|

October 11th, 2012, 09:14 AM
|
 |
Likely to be eaten by a grue.
|
|
Join Date: Oct 2006
Location: Pennsylvania, USA
|
|
|
"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.
|

October 11th, 2012, 09:29 AM
|
|
Contributing User
|
|
Join Date: Apr 2001
Posts: 909
Time spent in forums: 5 Days 5 h 34 m 32 sec
Reputation Power: 0
|
|
|
Sorry added the end of the code I have searched and cannot find out why
|

October 11th, 2012, 09:35 AM
|
 |
Likely to be eaten by a grue.
|
|
Join Date: Oct 2006
Location: Pennsylvania, USA
|
|
|
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.
|

October 11th, 2012, 09:36 AM
|
|
|
|
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.
|

October 11th, 2012, 04:47 PM
|
|
|
Quote: | 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!
|

October 12th, 2012, 08:31 AM
|
 |
Likely to be eaten by a grue.
|
|
Join Date: Oct 2006
Location: Pennsylvania, USA
|
|
|
I saw. Believe me, I saw.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|