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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.