ninabarley Posted August 5, 2009 Share Posted August 5, 2009 :facewall:I'm pulling my hair out...I've written a simple php file upload, and it seems to work fine. But once the file is in the directory, I get a 403 Forbidden error on it. I'm pretty sure it's because the permissions on it are wrong, but I don't know how to direct PHP to set it so that the file can be read when I link to it in my HTML (or any other way). Here's the code I used: <form action="<?php print $PHP_SELF?>" enctype="multipart/form-data" method="post"> Daily Bulletin: <input type="file" name="daily_bulletin" value="" /><br /> <p><input type="submit" name="submit" value="Upload New Daily Bulletin" /></p> </form> <?php define ("FILEREPOSITORY","./"); if (is_uploaded_file($_FILES['daily_bulletin']['tmp_name'])) { if (($_FILES['daily_bulletin']['type'] = "application/pdf") || ($_FILES['daily_bulletin']['type'] = "application/x-pdf")) { $extension = end(explode('.', $_FILES['tmp_name'])); $allowed = array('pdf', 'pdfx'); if (in_array($extension, $allowed)) { $name = $_POST['name']; $result = move_uploaded_file($_FILES['daily_bulletin']['tmp_name'], FILEREPOSITORY."/bulletins/bulletin.pdf"); if ($result == 1) { echo "<p>File successfully uploaded.</p>"; } else echo "<p>There was a problem uploading the file.</p>"; } else { echo "<p>Daily Bulletin must be uploaded in PDF format.</p>"; } #endIF } #endIF ?> Quote Link to comment https://forums.phpfreaks.com/topic/169012-php-upload-results-in-forbidden-files/ Share on other sites More sharing options...
ldougherty Posted August 5, 2009 Share Posted August 5, 2009 So the file does upload without issue but you can't access it via the URL once uploaded right? What are the permissions on the uploaded file, it should be at least 644 to be web accessible. You can use chmod and chown via PHP to change the file permissions directly in your script or figure out why it's being uploaded with minimal permissions in the first place. Quote Link to comment https://forums.phpfreaks.com/topic/169012-php-upload-results-in-forbidden-files/#findComment-891757 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.