I won't break out or show the lengthy code in actually building the PDF itself because I know the file generation is working fine.
When I try the following:
$pdf->Output('abc.pdf', 'F');
I receive error:
FPDF error: Unable to create output
file: abc.pdf
By changing the Output destination to 'D' or 'I':
$pdf->Output('abc.pdf', 'D');
The user is prompted to download the pdf that was generated and is done so successfully (views fine). The error makes me think it is a permissions error but fpdf should have access to write a pdf file to the directory the action is already occurring in correct?
Anybody dealt with this before?
If your PHP script is executed from a web-page (served by Apache, it is), then this code will be executed by the Apache (sometimes called www-data) user.
So, your Apache user needs to be able to write to the directory you're trying to write to.
Typically, you might have to give the write privilege to the other users of your system, using something like this from a command-line :
chmod o+w your_directory
The software you're using to upload your source files, if doing so using a GUI, should allow you to do that with a couple of chekboxes -- you need to check the "write" checkbox for the "others" users.
chmod o+w your_directory fixed it for me :)
Related
I have built an application using laravel that uploads pdf files to the public/pdfs/books/ folder. Then I am trying to create a pop up window that will display the uploaded file using the url.Bit while trying to view the file using my pop up box I am getting the following error.
Not allowed to load local resource: file:///C:/laragon/www/Uploader/public/pdfs/books/book.pdf
Can anyone suggest why I am getting this error? I even tried to load the file from another directory outside the application and got the same error. How Can I view the file from my application uploaded to folder
You shouldn't use the folder url like this. Because your application is running in local server So it should be able to view the file that starts with http.
To make the link for view use the following code in blade:
{{URL:to('/').'pdfs/abstracts/fillename.pdf'}}
Or use similar type of mechanism so the file is loaded with http protocol instead of from local directory starting with file:///C:
Can you view the file from browser?
file:///C:/laragon/www/Uploader/public/pdfs/books/book.pdf
If not, you should recheck your upload code.
Looks like permission issue, try chmod 775 -R * command in your /Uploader/public/pdfs directory. You could also try changing file permission in cpanel
I am in the process of setting up the godaddy file permissions and I do not know what permissions to set for my PHP files. They should be able to read, write and execute effecting the SQL server. Which options should I select, the default permissions are shown in the image below.
PHP files should only have the EXECUTE permission for all 3 groups
php files are executed, not read, like html files for example
if you leave read, people can with some tricky methods view your actual php code and steal it, so don't leave read on .php files
I have created a php file which will open a text file(which resides in the same location along with the php file),and i also added some code thus i can change the content of the text file.It was working great in my local host but as soon as i upload the folder to a server i cant save the changed content to the file some permission related error is coming up.Is there any way thus i can forcefully change the content of the file in server?I mean is there any way thus this permission related issues can be overcome?
Access it via FTP and change the permissions to 755 which allows everyone to read / execute and only yourself to write.
Read more about permissions to find what best suits your requirements.
I am trying to create a really simple webpage in php, letting people upload images to a folder on my server. I made this really simple with some done code, and it worked awesomely on my computer with xampp, but when I upload the page to my server, it gets an error message every time I upload anything. The error is when the script checks if the image was uploaded, where it says
$copied = copy($_FILES['image']['tmp_name'], $newname);
if(!$copied)
echo "error";
This leads me to believe that there is something wrong with the permissions. But how can I set this? And what should I set it to? I just need others to be able to upload images to a spesific folder.
The web server needs write permissions to be able to write into the directory you're storing the images.
Assuming you're on a Linux server, run the following command on the server (ssh) after changing /path/to/uploaded/images to the image upload directory, and see if it solves the problem:
chmod 777 /path/to/uploaded/images
If that fixes the problem, you can probably relax the permissions to something like:
chmod 664 /path/to/uploaded/images
These are basic commands for directory permissions, which you can learn more about in this tutorial about file permissions on Linux.
Alternatively, you can use move_uploaded_file() to copy the uploaded file to a known location.
I have read the following tutorial "Uploading Files To the Server Using PHP"
and have several questions related to the topics.
Q1> The tutorial mentions that
"Note that PHP must have write access
to $uploadDir or else the upload will
fail"
For me, I only allow the user to upload the file after the user has login to the website.
If we set that $uploadDir permission as 777, then everyone can have written permission to that folder. How to avoid this problems?
Also I am using WAMP as my testing bed, can I simulate the same case as a real web server?
Q2> In order to prevent Preventing direct access, the tutorial mentions:
"A better approach is to move the
upload directory away from your web
root. For example, the web root for
this site is:
/home/arman198/public_html/ to prevent
direct listing i can set the upload
directory to /home/arman198/upload/."
Now my problem is that how can I display the uploaded images on other website pages. Since, the upload is not accessible directly anymore? I need to display the uploaded image save personal headshot dynamically on other website page. Is it possible?
Thank you
It's a common problem.
All modern computers have a temporary files directory. On Linux/Unix it's /tmp, on Windows it's usually c:\temp. The OS install will have set permissions on that directory so that anyone can write files there but only privileged users can delete files that don't belong to them. This is where PHP will want to put an uploaded file; your application then has to move it elsewhere (this is the purpose of the move_uploaded_file() function). PHP under Windows may need upload_tmp_dir actually set in the php.ini file.
Once you have an uploaded file, you can shift it whereever you like, including to where the webserver can read it to serve it. The biggest problem with that it is awfully easy to put this directory inside your codebase. Don't do that. As soon as you do anything beyond editing the files inside the directory they are served from, it will be problematic. Trust me: I've dealt with a few times this in code I've inherited. It's easy to let your webserver load files from a location outside your codebase.
The other alternative is to produce a download script. That way the file need not be servable by the webserver at all. One disadvantage is that you don't get to leverage the web server's MIME translation, but then, that lets you control which types of image files are permitted.
For the second question, you can use a PHP script intead of direct access to the directory. Lets name it image.php. Lets assume that it can take a parameter id, like image.php?id=image_id. In that file you can get the id using superglobal array $_GET. Then you can search for images with that Id and just send it as response.
First one I'm not sure, but maybe play with .htaccess file.
And for the first question, try setting your permissions to 775. That should allow PHP to write the file to the directory without giving the general public write access.