Shibbir
Shibbir

Reputation: 2031

Access to WordPress upload directory through url is showing 403 error message

I have an application in WordPress where I have saved a pdf file to the wp-content/uploads/ccroipr-pdf/ folder.

The code is something like that to create and save the PDF file:

$upload         = wp_upload_dir();
$upload_dir     = $upload['basedir'];
$upload_dir     = $upload_dir . '/ccroipr-pdf/';

if (! is_dir($upload_dir)) {
    mkdir( $upload_dir, 0700 );
}        

$filename= $confirm_id.'.pdf';      
$pdf->Output($upload_dir.$filename,'F');

Now when I access the file using this URL:

http://example.com/wp-content/uploads/ccroipr-pdf/ccroipr-20200511090236163.pdf

It's showing me 403 error message?

Is that for the directory permission? If so then which permission I should write for the download only?

Upvotes: 0

Views: 917

Answers (1)

Howard E
Howard E

Reputation: 5649

The recommended file permissions for wordpress folders is 0755 not 0700 -

The owner is your user on the server or your apache name, not the user of your site.

So changing the permission to 0700 will not make it download only, but rather so that all guests to the site can't even access the files to download them at all.

Upvotes: 1

Related Questions