Uploading Files

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
User avatar
evilmonkey
Forum Regular
Posts: 823
Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada

Uploading Files

Post by evilmonkey »

Hello. I made a little script to upload a jpeg picture to my server and I'm testing it out on my Windows machine. here is the form I use:

Code: Select all

<HTML>
<body>
<form enctype="multipart/form-data" method="POST" action="submit2.php">
<input type="hidden" name="MAX_FILE_SIZE" value="51200">
<input type="hidden" name"foo" value="bar">
<input type="file" name="fupload"><br>
<input type="submit" value="Send file!">
</form>
</body>
</html>
and here is submit2.php

Code: Select all

<?php
$file_dir = "C:\\Inetpub\\wwwroot\\pc-dna\\pics";
$file_url = "http://localhost/pc-dna/pics";
 
foreach( $HTTP_POST_FILES as $file_name => $file_array ) {
print "path: ".$file_array['tmp_name']."<br>\n";
print "name: ".$file_array['name']."<br>\n";
print "type: ".$file_array['type']."<br>\n";
print "size: ".$file_array['size']."<br>\n";
 
if ( is_uploaded_file( $file_array['tmp_name'] ) 
&& $file_array['type'] == "image/pjpeg" ) {
move_uploaded_file( $file_array['tmp_name'], "$file_dir".$file_name) 
or die ("Couldn't copy");
print "<img src="$file_url/$file_name"><p>\n\n";
  }
}
echo "Success";
?>
The problem is this:

Code: Select all

path: C:\WINDOWS\TEMP\php2C.tmp
name: image012.jpg
type: image/pjpeg
size: 6551

Warning: move_uploaded_file(C:\Inetpub\wwwroot\pc-dna\pics\fupload) &#1111;function.move-uploaded-file]: failed to create stream: Permission denied in c:\inetpub\wwwroot\pc-dna\submit2.php on line 17

Warning: move_uploaded_file() &#1111;function.move-uploaded-file]: Unable to move 'C:\WINDOWS\TEMP\php2C.tmp' to 'C:\Inetpub\wwwroot\pc-dna\pics\fupload' in c:\inetpub\wwwroot\pc-dna\submit2.php on line 17
Couldn't copy
I am running my machine as an administrator with all the priveleges enabled. I have also checked and double checked that the above folders exist, yet it still can't create the file. I am running PHP 4.3.1 on IIS 5.0 with MySQL 3.23.xx. Please help.

Thanks.
User avatar
evilmonkey
Forum Regular
Posts: 823
Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada

Post by evilmonkey »

I think I found half my problem. I connected to my computer's FTP server as the system administrator, and noticed that the folder pics is chmodded 555. I tried setting it to 755 and 777, but it doesn't seem to work. Could that be my problem? How do I set 777 on IIS? (through the FTP client doesn't seem to work)

Cheers!
User avatar
evilmonkey
Forum Regular
Posts: 823
Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada

Post by evilmonkey »

Soooo....

Can anyone help me?

Cheers!
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Depending on which version of Windows you are running - you may be able to alter permissions by right-clicking on the folder, going to the security tab and making sure that the IUSR_yourcomputernamehere account has read and write permissions.

You may want to check the Microsoft website for information for you specific version.

Mac
Post Reply