Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-02-2008, 11:31 PM   PM User | #1
peteyb383
Regular Coder

 
Join Date: Mar 2008
Posts: 118
Thanks: 3
Thanked 9 Times in 9 Posts
peteyb383 is an unknown quantity at this point
PHP, IIS 7, File Upload Problems

Hi,

I recently started hosting my own website on my computer, instead of a third party hosting site. I set up the databases, included PHP and everything was running fine under IIS 7 on Vista. However, I have a file upload script that no longer works on my site. the code stayed the same from the other hosting service and on my computer. So I am basically asking whether there a setting or something that needs to be changed in order to allow file upload. In my fileupload.php code, it returns "Invalid File" when the criteria for the image is not met, and every time I try to upload a file in the criteria, I receive that error.

Here is my code:

PHP Code:
<form accept-charset="UNKNOWN" action="fileupload.php" method="post" enctype="multipart/form-data">
<
label for="file">Picture Filename:</label>
<
input type="file" name="file" id="file" /> 
<
br />
<
input type="submit" name="submit" value="Submit" />
</
form


fileupload.php:


PHP Code:
<?php
if ((($_FILES["file"]["type"] == "image/gif")
|| (
$_FILES["file"]["type"] == "image/jpeg")
|| (
$_FILES["file"]["type"] == "image/pjpeg"))
&& (
$_FILES["file"]["size"] < 850000))
  {
  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("uploads/" $_FILES["file"]["name"]))
      {
      echo 
$_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      
move_uploaded_file($_FILES["file"]["tmp_name"],
      
"uploads/" $_FILES["file"]["name"]);
      echo 
"Stored in: " "uploads/" $_FILES["file"]["name"];
      }
    }
  }
else
  {
  echo 
"Invalid file";
  }
__________________
Petey

View my Blog and Support my Mission!

Last edited by peteyb383; 03-02-2008 at 11:34 PM..
peteyb383 is offline   Reply With Quote
Old 03-03-2008, 12:07 AM   PM User | #2
_Aerospace_Eng_
Supreme Master coder!


 
_Aerospace_Eng_'s Avatar
 
Join Date: Dec 2004
Location: In a place far, far away...
Posts: 19,293
Thanks: 2
Thanked 1,044 Times in 1,020 Posts
_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light
Are you getting any errors? You may have to set the permissions on the folder that you are trying to upload to.
__________________
||||If you are getting paid to do a job, don't ask for help on it!||||
_Aerospace_Eng_ is offline   Reply With Quote
Old 03-03-2008, 12:25 AM   PM User | #3
peteyb383
Regular Coder

 
Join Date: Mar 2008
Posts: 118
Thanks: 3
Thanked 9 Times in 9 Posts
peteyb383 is an unknown quantity at this point
I'm not getting any errors surprisingly. It's just skipping down to the "else statement" as if the image does not fit the criteria.

Also, I have shared the uploads folder with "IIS_IUSRS" making it a co-owner. I am a little unfamiliar with Vista but to my knowledge making IIS a co owner give it all privileges to the directory.

The php.ini file I have allows file uploads with a max limit of 2MB, which I am well under, It just seems weird that the same code works with my other host, but not when I myself host my site.

Thanks for any/anymore input provided.
__________________
Petey

View my Blog and Support my Mission!
peteyb383 is offline   Reply With Quote
Old 03-03-2008, 12:44 AM   PM User | #4
_Aerospace_Eng_
Supreme Master coder!


 
_Aerospace_Eng_'s Avatar
 
Join Date: Dec 2004
Location: In a place far, far away...
Posts: 19,293
Thanks: 2
Thanked 1,044 Times in 1,020 Posts
_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light
I know you aren't using wordpress but the tips here might help.
http://joseph.randomnetworks.com/arc...oads-with-iis/
__________________
||||If you are getting paid to do a job, don't ask for help on it!||||
_Aerospace_Eng_ is offline   Reply With Quote
Old 03-03-2008, 12:48 AM   PM User | #5
firepages
Super Moderator


 
Join Date: May 2002
Location: Perth Australia
Posts: 3,890
Thanks: 5
Thanked 79 Times in 78 Posts
firepages will become famous soon enough
what do you see when you
PHP Code:
<?php print_r($_FILES);?>
?
__________________
resistance is...

MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)
firepages is offline   Reply With Quote
Old 03-03-2008, 12:56 AM   PM User | #6
CFMaBiSmAd
Senior Coder

 
CFMaBiSmAd's Avatar
 
Join Date: Oct 2006
Location: Denver, Colorado USA
Posts: 2,711
Thanks: 2
Thanked 251 Times in 243 Posts
CFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the rough
I keep seeing that same crappy upload code. Where are people copying that from?

It does not check the ['error'] element until after it checks the ['type'] and ['size']. People, if there is an error, the type and size will be empty and testing them will fail. You must check for errors before you ever touch any of the data.

Also, by combining all the type and size testing into one conditional statement and one error message, you will never know which test failed.

The error message, which is just echo "Invalid file"; now, needs to output a meaningful message as to what exactly was wrong and what the value was, for example echo $_FILES["file"]["type"]; as part of the error so that you know what was actually received.

It is likely that file uploading is disabled on your server or the temp location for uploading files to does not exist or does not have the proper permissions. You need to check all the runtime values related to uploads using a phpinfo() statement.

I won't even suggest turning on full php error reporting and then checking your web server log file because you probably did those troubleshooting steps before posting your problem in a forum.
__________________
If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.
CFMaBiSmAd is offline   Reply With Quote
Old 03-03-2008, 12:57 AM   PM User | #7
peteyb383
Regular Coder

 
Join Date: Mar 2008
Posts: 118
Thanks: 3
Thanked 9 Times in 9 Posts
peteyb383 is an unknown quantity at this point
Quote:
what do you see when you
PHP Code:
<?php print_r($_FILES);?>
?

Parse error: syntax error, unexpected T_STRING in C:\inetpub\wwwroot\fileupload.php on line 7


I get the above error...
__________________
Petey

View my Blog and Support my Mission!

Last edited by peteyb383; 03-03-2008 at 12:32 PM..
peteyb383 is offline   Reply With Quote
Old 03-03-2008, 05:36 AM   PM User | #8
CFMaBiSmAd
Senior Coder

 
CFMaBiSmAd's Avatar
 
Join Date: Oct 2006
Location: Denver, Colorado USA
Posts: 2,711
Thanks: 2
Thanked 251 Times in 243 Posts
CFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the rough
The posted code does not produce that error. In fact, the posted code does not produce any fatal php parse errors.

You would need to post the actual code that caused that error to get help with what is causing it.
__________________
If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.
CFMaBiSmAd is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:32 AM.


Advertisement
Log in to turn off these ads.