Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 136,492 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,710 people online right now. Registration is fast and FREE... Join Now!




Invalid File

2 Pages V  1 2 >  
Reply to this topicStart new topic

Invalid File

GorillaCheif
4 Mar, 2008 - 03:54 PM
Post #1

D.I.C Head
**

Joined: 23 Apr, 2006
Posts: 62


My Contributions
This is being called from a file upload form. Regardless of the tweaks and strings I pull on this, I keep getting an invalid file message.
I know I missed something probably simple, but being relatively new to php, I can't seem to spot it.
Thanks in advance


CODE
<?php

if ((($_FILES["file"]["type"] == "application/msword")
|| ($_FILES["file"]["type"] == "application/pdf")
|| ($_FILES["file"]["type"] == "image/tiff")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "application/eps "))
&& ($_FILES["file"]["size"] < 10000000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Error: " . $_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 "Stored in: " . $_FILES["file"]["tmp_name"];
    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";
  }
?>

User is offlineProfile CardPM
+Quote Post

no2pencil
RE: Invalid File
4 Mar, 2008 - 03:58 PM
Post #2

My fridge be runnin OH NOEZ!
Group Icon

Joined: 10 May, 2007
Posts: 6,465



Thanked: 66 times
Dream Kudos: 2425
Expert In: Goofing Off

My Contributions
What is the file name that you are trying to upload?

CODE

if ((($_FILES["file"]["type"] == "application/msword")
|| ($_FILES["file"]["type"] == "application/pdf")
|| ($_FILES["file"]["type"] == "image/tiff")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "application/eps "))
&& ($_FILES["file"]["size"] < 10000000))

The error message that you are getting is the else to this if. So this is the statement that is failing & forcing you into the else code block, reporting the error.
User is online!Profile CardPM
+Quote Post

GorillaCheif
RE: Invalid File
4 Mar, 2008 - 04:31 PM
Post #3

D.I.C Head
**

Joined: 23 Apr, 2006
Posts: 62


My Contributions
QUOTE
The error message that you are getting is the else to this if.

That's what I figured. I've tried various files, PDF, DOC, TIFF and JPG with the same results.

This post has been edited by GorillaCheif: 4 Mar, 2008 - 04:52 PM
User is offlineProfile CardPM
+Quote Post

no2pencil
RE: Invalid File
4 Mar, 2008 - 07:32 PM
Post #4

My fridge be runnin OH NOEZ!
Group Icon

Joined: 10 May, 2007
Posts: 6,465



Thanked: 66 times
Dream Kudos: 2425
Expert In: Goofing Off

My Contributions
1.) Try to use the file name extension
2.) In your error, output the value of $_FILES["file"]["type"] to get a better idea of what's going on with the code.

php

echo "File type ".$_FILES['file']['type']." is not supported";

User is online!Profile CardPM
+Quote Post

GorillaCheif
RE: Invalid File
5 Mar, 2008 - 08:42 AM
Post #5

D.I.C Head
**

Joined: 23 Apr, 2006
Posts: 62


My Contributions
QUOTE(no2pencil @ 4 Mar, 2008 - 09:32 PM) *

1.) Try to use the file name extension
2.) In your error, output the value of $_FILES["file"]["type"] to get a better idea of what's going on with the code.

php

echo "File type ".$_FILES['file']['type']." is not supported";



Isn't that what I'm doing?
User is offlineProfile CardPM
+Quote Post

SpaceMan
RE: Invalid File
5 Mar, 2008 - 09:28 AM
Post #6

D.I.C Regular
Group Icon

Joined: 20 Feb, 2003
Posts: 270

plz post the form tag, and inputs
User is offlineProfile CardPM
+Quote Post

SpaceMan
RE: Invalid File
5 Mar, 2008 - 11:03 AM
Post #7

D.I.C Regular
Group Icon

Joined: 20 Feb, 2003
Posts: 270

i was looking at it, and some things did seem logical to me, i code a bit different then some.

anyway, this works.
php

<?php

//$_FILES["file"]["type"]
$types = array('image/pjpeg','image/tiff','application/pdf','application/msword','application/eps');


//be aware that if this is above server http root, someone can delete them.
//is beter to store below it and use another page to get them, that has cleaning for the dir name and file name.
$upload_dir = 'upload/';

if(!is_writable($upload_dir)) exit($upload_dir.' Dir is not writable.');

if($_FILES["file"]["size"] > 0)
if ($_FILES["file"]["size"] < 10000000){
if(!in_array($_FILES["file"]["type"],$types)){
echo '"'.$_FILES["file"]["type"].'" File type not allowd.';

} else
if (is_file($upload_dir . $_FILES["file"]["name"])){

echo '"'.$_FILES["file"]["name"].'" already exists. rename and try again.';

} else {


if ($_FILES["file"]["error"] > 0){
echo 'Error: ' . $_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 'Stored in: ' . $_FILES["file"]["tmp_name"];


if(move_uploaded_file($_FILES["file"]["tmp_name"],$upload_dir . $_FILES["file"]["name"]))
echo '<br>Stored in: ' . $upload_dir . $_FILES["file"]["name"];
else
echo '<br>Error moving file to: ' . $upload_dir;

}
}
} else {
echo 'File to big.';
}
?>

<form method='post' enctype="multipart/form-data">
<input name="file" type="file"><br>
<input type="submit">
</form>


hmm, seems i am having issues posting code with html line breaks.

This post has been edited by SpaceMan: 5 Mar, 2008 - 11:05 AM
User is offlineProfile CardPM
+Quote Post

GorillaCheif
RE: Invalid File
5 Mar, 2008 - 11:18 AM
Post #8

D.I.C Head
**

Joined: 23 Apr, 2006
Posts: 62


My Contributions
Ok, here is the form.

CODE

<body leftmargin="0px" topmargin="0px" marginwidth="0px" marginheight="0px">
<table width="255" height="650px" border="0" cellspacing="0" cellpadding="20" topmargin="0" leftmargin="0">
  <tr>
    <td width="250" valign="top"><span class="style1">submit </span><br/>
    <span class="style9">send us your documents for printing</span><br/><br/><br/>
    <div>
      
      <form id="submit form" name="submit" method="get" action="http://www.xxxx.com/php/upload.php" >
      <input type="hidden" name="recipient" value="xxxx@xxxx.com">
      <input type="hidden" name="subject" value="Document submission">
        <label><span class="style8">name</span><br/>
        <input type="text" hidden="required" name="name" id="name" tabindex="1" />
          </label><br/>
          <label><span class="style8">email</span><br/>
        <input type="text"hidden="required" name="email" id="email" tabindex="2" />
          </label><br/>
            <label><span class="style8">company</span><br/>
        <input type="text" hidden="required"name="company" id="company" tabindex="3" />
          </label><br/>
           <label><span class="style8">phone</span><br/>
        <input type="text" hidden="required"name="phone" id="phone" tabindex="4" />
          </label><br/><br/>
           <label>
           <div align="right"><span class="style8">quantity</span>
             <input name="quantity" type="text" hidden="required" id="quantity" tabindex="5" value="" size="3" maxlength="4" />
            </div>
          </label>
          <label>
      <div align="right"><span class="style8">size</span>
                <select name="paper" hidden="required" id="select" tabindex="6">
                   <option>8 1/2 x 11</option>
                   <option>8 1/2 x 14</option>
                   <option>11 x 17</option>
                   </select>
            </div>
          </label>
          <label>
      <div align="right"><span class="style8">paper type</span>
                <select name="paper2" hidden="required" size="1" id="select" tabindex="7">
                   <option>20lb bond</option>
                   <option>20lb cotton*</option>
                   <option>20lb color*</option>
                   <option>40lb gloss</option>
                   <option>AstroBrite*</option>
                   <option>Skytone*</option>
            </select>
          </div>
          </label>
           <div align="right">
             <p><span class="style13">* only available in 8 1/2 x 11<br/>We can only accept Microsoft Word, PDF or image files.</span>
              
               <input name="document" hidden="required" type="file" size="15" tabindex="8"/>
               <br/>
               <label>
               <textarea name="SI" id="SI" cols="27" rows="3" tabindex="9">Specify paper color and other special instructions here.</textarea>
               </label>
               <br/>
               <input name="submit" type="submit" value="send" tabindex="10"/>
               <input type="hidden" name="env_report" value="REMOTE_HOST, REMOTE_ADDR">
               <input type="hidden" name="redirect"value="thanks.html" />
               <br/>
               <br/>
             </p>
          </div>
      </form>


*edit* code.gif
User is offlineProfile CardPM
+Quote Post

SpaceMan
RE: Invalid File
5 Mar, 2008 - 11:24 AM
Post #9

D.I.C Regular
Group Icon

Joined: 20 Feb, 2003
Posts: 270


the form tag has to have enctype.
i have not tryed one with a get, after and the enctype if it does not work try change to post.

also the input name is wrong, change to file.
is what you have in the array _FILE['input_name']
yous is name="document" for type=file

This post has been edited by SpaceMan: 5 Mar, 2008 - 11:26 AM
User is offlineProfile CardPM
+Quote Post

GorillaCheif
RE: Invalid File
5 Mar, 2008 - 11:34 AM
Post #10

D.I.C Head
**

Joined: 23 Apr, 2006
Posts: 62


My Contributions
Thanks, I did change the upload dir.
and I did manage to debug most of this code, however i'm having a problem with the upload dir being un-writable.
I've set it to write and still no change.
User is offlineProfile CardPM
+Quote Post

SpaceMan
RE: Invalid File
5 Mar, 2008 - 11:47 AM
Post #11

D.I.C Regular
Group Icon

Joined: 20 Feb, 2003
Posts: 270

must be a *nix server?
chmod via ftp to 0777

witch is , right click the dir, to propertise.
click all the check boxs, or input 0777.

hhmmmm..
you say moved the dir, use /full/server/to/upload/
User is offlineProfile CardPM
+Quote Post

GorillaCheif
RE: Invalid File
5 Mar, 2008 - 11:49 AM
Post #12

D.I.C Head
**

Joined: 23 Apr, 2006
Posts: 62


My Contributions
QUOTE(SpaceMan @ 5 Mar, 2008 - 01:46 PM) *

must be a *nix server?
chmod via ftp to 0777

witch is , right click the dir, to propertise.
click all the check boxs, or input 0777.



Yup, did that and the form input is correct. If I were change it, I lose a submit button.
User is offlineProfile CardPM
+Quote Post

2 Pages V  1 2 >
Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 07:45PM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month