file upload problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
charlie_d
Forum Newbie
Posts: 3
Joined: Mon Mar 03, 2008 11:21 am

file upload problem

Post by charlie_d »

I am using php 5.2.5 and IIS 5.1 on MS Windows Pro with SP2 installed

I am attempting a simple file upoad with first page:

Code: Select all

<form enctype="multipart/form-data" action="test_uploadck.php" method="POST">
    <!-- MAX_FILE_SIZE must precede the file input field -->
    <input type="hidden" name="MAX_FILE_SIZE" value="75000" />
    <!-- Name of input element determines name in $_FILES array -->
    Send this file: <input name="userfile" type="file" />
    <input type="submit" value="Send File" />
</form>
and test_uploadck.php:

Code: Select all

<?php
ini_set ("display_errors", "1");
error_reporting(E_ALL);
print "<pre>";
 
$target_path = 'Images/';
$target_path = $target_path . basename( $_FILES['userfile']['name']); 
 
if(move_uploaded_file($_FILES['userfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['userfile']['name']). 
    " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}
 
echo 'Here is some more debugging info:';
print_r($_FILES);
 
print "</pre>";
?>
I get the following errors:

Code: Select all

Warning:  move_uploaded_file(Images/AL19307A.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in C:\Inetpub\wwwroot\estateagent1\test_uploadck.php on line 18
 
Warning:  move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\PHP\tmp\php43.tmp' to 'Images/AL19307A.jpg' in C:\Inetpub\wwwroot\estateagent1\test_uploadck.php on line 18
I have checked the standard pitfalls as follows:

a) the file being uploaded was not too big (only 22K) and did not exceed either MAX_FILE_SIZE (750000) in the script or post_max_size and upload_max_filesize (both 8M) in php.ini.
b) the folder I was moving the uploaded file to exists and has all permissions enabled in IIS
c) There were no normal input fields in the upload form

Where am I going wrong?
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Re: file upload problem

Post by Zoxive »

Permission denied
Are you sure ISS / PHP has permission?
kryles
Forum Contributor
Posts: 114
Joined: Fri Feb 01, 2008 7:52 am

Re: file upload problem

Post by kryles »

If you are on a shared server they may have this feature disabled. That is what happened to me, and they told me I'd need a dedicated server for this to work.
charlie_d
Forum Newbie
Posts: 3
Joined: Mon Mar 03, 2008 11:21 am

Re: file upload problem

Post by charlie_d »

I am using my local machine - no network.

Am I sure that IIS and Php have permissions set? .... No i am not. I have opened IIS manager and clicked th relevant tick boxes in the profile for the default webiste and checked all of the relevant subfolders to be sure. What else might I need to do?
charlie_d
Forum Newbie
Posts: 3
Joined: Mon Mar 03, 2008 11:21 am

Re: file upload problem

Post by charlie_d »

Thanks all for your help but problem now solved

It was a security issue - I had assumed that the directory security in IIS and making sure read only was unchecked in Windows Explorer would be enoughas this was all I could see. However I found some info at http://www.ekhoury.com/2007/01/15/permi ... hp-on-iis/ which fixed the problem:
On Windows Server 2003, it’s not an issue and the user can figure out the solution easily by opening the properties of the folder and working with the security tab which I’ll explain later on.

On the other hand, Windows XP users have that security tab hidden. I kept on unchecking the Read-Only, but it was rechecked automatically! The trick is to show the Security Tab in the properties window of the folder. Windows XP have this option hidden; to show it follow the following procedure:


- Open My Computer
- Tools > Folder Options
- Go to the View tab
- In the bottom of the list uncheck “Use simple file sharing (Recommended)”

Now you will have the security tab shown in the properties of every folder. Now, to give write access to PHP in order to fopen, copy or upload a file, follow this procedure:

- Right click on the folder where you want give write access
- Properties
- Go to the Security tab
- Select the Internet Guest Account ([username]/IUSR_[username])
- Allow the Write and Modify access. (You can give full permission)
- Then press Ok.

Your write access should be working by now. Happy coding!
Post Reply