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
elecktricity
Forum Contributor
Posts: 128
Joined: Sun Sep 25, 2005 8:57 pm
Location: Trapped in my own little world.
Contact:

Uploading Files

Post by elecktricity »

This dosnt seem to work right...

add.php

Code: Select all

<form enctype=\'image/gif\' action=\'add2.php\' method=\'POST\'>
    <input type=\'hidden\' name=\'MAX_FILE_SIZE\' value=\'70000\' />
    Send this file: <input class=\'text\' name=\'userfile\' type=\'file\' />
    <input class=\'text\' type=\'submit\' value=\'Send File\' />
</form>

add2.php

Code: Select all

<?php
$uploaddir = '/home/rootbee/public_html/vividgamers/iconrush/icons/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
echo 'Success';
} else {
echo 'Failure';
}

print "</pre>";

?>
keeps saying going to the else and saying failure... not sure whats going wrong
User avatar
Skittlewidth
Forum Contributor
Posts: 389
Joined: Wed Nov 06, 2002 9:18 am
Location: Kent, UK

Post by Skittlewidth »

I think the enctype has to be "multipart/form-data", even if its just images you're uploading.
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post by foobar »

Skittlewidth wrote:I think the enctype has to be "multipart/form-data", even if its just images you're uploading.
Yep. This is compulsory for file uploads. Otherwise, it won't be sent correctly.
User avatar
elecktricity
Forum Contributor
Posts: 128
Joined: Sun Sep 25, 2005 8:57 pm
Location: Trapped in my own little world.
Contact:

Post by elecktricity »

I switched it to that and its still doing about the same thing... here is the error...



Code: Select all

Warning:  move_uploaded_file(/home/rootbee/public_html/site1/dir/image.gif): failed to open stream: Permission denied in /home/rootbee/public_html/site1/dir/add2.php on line 5



Warning:  move_uploaded_file(): Unable to move '/tmp/phpwAS0kf' to '/home/rootbee/public_html/site1/dir/image.gif' in /home/rootbee/public_html/site1/dir/add2.php on line 5

Failure
programmermatt
Forum Commoner
Posts: 65
Joined: Tue Mar 15, 2005 5:03 pm
Contact:

Post by programmermatt »

Apache doesn't have permission to put the file in that directory apperently
User avatar
elecktricity
Forum Contributor
Posts: 128
Joined: Sun Sep 25, 2005 8:57 pm
Location: Trapped in my own little world.
Contact:

Post by elecktricity »

how do I give it permission? I believe the permission is at 777
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post by foobar »

elecktricity wrote:how do I give it permission? I believe the permission is at 777
Make the permission of the directory 777 or 666. If this isn't on your comp, than maybe your host has a file-size restriction.
Post Reply