Jump to content

PHP Upload results in forbidden files


ninabarley

Recommended Posts

: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

?>

 

Link to comment
https://forums.phpfreaks.com/topic/169012-php-upload-results-in-forbidden-files/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.