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

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




Problems after using PHP upload script

 
Reply to this topicStart new topic

Problems after using PHP upload script, I get a 403 Forbidden error

gadgetsguru
post 31 May, 2008 - 01:26 PM
Post #1


New D.I.C Head

*
Joined: 7 Oct, 2006
Posts: 18


My Contributions


Hi everyone!
I created a PHP upload script and it is successful in uploading the files; however, when I try to access the files on my web hosting provider (Yahoo! Small Business), I get a 403 Forbidden error. Is this because of my script or is it something I need to contact Yahoo! Small Business about? Please help!

Below is the script I used...

CODE
<?php
if (array_key_exists('_submit_check', $_POST)) { // If uploaded file exists
$uploadTo = "uploads/"; // Where the file is going to be placed

/* Add the original filename to our target path.
Result is "uploads/filename.extension" */
$uploadTo = $uploadTo . basename($_FILES['userfile']['name']);
$_FILES['userfile']['tmp_name'];
}
?><html>
<head>
<title>Upload script</title>
</head>
<body>
<form enctype="multipart/form-data" action="upload.php" method="post">
<input type="hidden" name="_submit_check" value="1">
<input type="hidden" name="MAX_FILE_SIZE" value="4194304">
File: <input name="userfile" type="file"> <input type="submit" value="Upload">
</form>
<?php
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadTo)) {
?>The file <a href="<?php echo $uploadTo; ?>" target="_top"><strong><?php echo basename($_FILES['userfile']['name']); ?></strong></a> was successfully uploaded.<?php
} elseif (array_key_exists('_submit_check', $_POST) && !move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadTo)) {
?>There was an error uploading the file, please try again!<?php } ?>
</body>
</html>


Thank you for your help! I really do appreciate it. biggrin.gif

This post has been edited by gadgetsguru: 31 May, 2008 - 02:10 PM
User is offlineProfile CardPM

Go to the top of the page

JBrace1990
post 31 May, 2008 - 04:14 PM
Post #2


D.I.C Regular

Group Icon
Joined: 9 Mar, 2008
Posts: 474



Thanked 21 times

Dream Kudos: 350
My Contributions


you would need to talk to the hosting company. it sounds like they won't allow access, and the server would need to be edited to allow it.
User is offlineProfile CardPM

Go to the top of the page

akozlik
post 31 May, 2008 - 04:41 PM
Post #3


D.I.C Addict

Group Icon
Joined: 25 Feb, 2008
Posts: 596



Thanked 22 times

Dream Kudos: 750
My Contributions


How are you trying to access the files?

Are you just trying to browse to 'http://www.yourdomain.com/uploadedfiles/' or wherever your files are stored?

If so, that's why you're getting the 403 error. 403 errors are regarding permissions, so they may not be set properly on your server. However, if you are try to access the directory as above, the 403 will get thrown for trying to access a directory without an index file. Try accessing your files with

http://www.yourdomain.com/uploadedfiles/filename.txt

Or whatever your filename is.

Hope that helps clarify a bit more.
User is offlineProfile CardPM

Go to the top of the page

gadgetsguru
post 31 May, 2008 - 07:46 PM
Post #4


New D.I.C Head

*
Joined: 7 Oct, 2006
Posts: 18


My Contributions


QUOTE(akozlik @ 31 May, 2008 - 06:41 PM) *

How are you trying to access the files?

Are you just trying to browse to 'http://www.yourdomain.com/uploadedfiles/' or wherever your files are stored?

If so, that's why you're getting the 403 error. 403 errors are regarding permissions, so they may not be set properly on your server. However, if you are try to access the directory as above, the 403 will get thrown for trying to access a directory without an index file. Try accessing your files with

http://www.yourdomain.com/uploadedfiles/filename.txt

Or whatever your filename is.

Hope that helps clarify a bit more.

Actually, I can access the folder just fine, but when I try to access the specific file, that's when I get the 403 Forbidden error. I think it does have something to do with permissions, but I'll have to start looking into that. I haven't the slightest idea on how to get/set file permissions. lol!

Anyways, thanks for the info! :-)
User is offlineProfile CardPM

Go to the top of the page

akozlik
post 31 May, 2008 - 09:16 PM
Post #5


D.I.C Addict

Group Icon
Joined: 25 Feb, 2008
Posts: 596



Thanked 22 times

Dream Kudos: 750
My Contributions


Does your ftp client allow for setting permissions? If so you should right click on the directory and set the permissions to full read/write/execute. If you can SSH into the site you could also chown the directory with

CODE

chown directory 777


If anything, check with your hosting service. You should be able to access files that are uploaded.
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 06:39AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month