Another dev and I are creating a website and we are using php to read/write to/from our site's directory. For some reason, everything on his end works fine but I can only get one type of I/O to work... If I modify my httpd.conf file and change the user:
User _www //Change this to my system user name (Spencer)
Group _www
I can upload image files to our directory, but as soon as I make that change, I can no longer read text files which causes an exception:
Uncaught SyntaxError: Unexpected token <
on this line:
var results = $.parseJSON(data);
If someone could help me better understand the relevant portion of the httpd.conf file I included above and help me with a direction for improving my setup, I would be very appreciative!
EDIT:
When I add a console.log(data) before the json parse, the output is <b>Warning</b>: chmod(): Operation not permitted in <b>/Users/Spencer/Programming/... and the error contains the text of the file I'm trying to open..
After digging into it more, it turns out this is what is causing the problem:
chmod($fileName, 0777);
and I guess that is a problem because the PHP user and the System user clash. I found some info about PHP and the chmod() function here
Removed irrelevant code
Related
I checked some similar questions here, but i didn't got an answer, solving my problem.
I use TCPDF to generate a PDF with PHP.
When I use the $pdf->Output($file_total, 'I');
it's all good and the file is shown in Browser.
If I use the save to localhost option $pdf->Output($file_total, 'F'); I get this error:
"failed to open stream: Permission denied in /opt/lampp/htdocs/project/tcpdf_min/include/tcpdf_static.php on line 1821"
"TCPDF ERROR: Unable to create output file"
The Path I set for saving the PDF file is: "/opt/lampp/htdocs/project/files/2021"
What am I doing wrong? is my path wrong?
The forced saving $pdf->Output($file_total, 'D'); works just fine, so i must doing something wrong with the path on mac...
please help!
Thanks
In comments we both went through possible reasons such as finding an absolute rather than relative location and checking out folder permissions for non admin process as that was also suspected. Thus between us the conclusion was:-
use address as
"localhost:8080/projects..."
and ensure target folder was set to permissions
"read/write" for all users
For production use the write access needs to be trimmed back to the process and admin, not all users.
I am working with PDFlib's php code in an aws server and I keep getting he following error message
Couldn't open PDF file 'file.pdf' for writing (permission denied)
I considered editing the permissions of this particular directory but the permissions are
drwxrwxrwx+
Which seem to be appropriate for this script to function. Anyone has any idea why I am getting this permissions error?
Thank you for the input I have discovered the error.
My issue was that I was not specifying the path to my output document and temp directory.
I was declaring my output document as :
$output_document = "file.pdf"
instead of
$output_document = "/path/to/output/file.pdf"
I have a site for media conversion where users can upload video, audio or image files and it is converted in to 3 popular formats. Conversion script works fine but I am having some issues with the tmp directory where the files get uploaded to. I have tried 2 scenarios I am fine with either but neither works and it seems to me to be permissions related but I can seem to fix the problem.
I am working locally right now while I work out the kinks.
Scenario 1:
File is uploaded to default local tmp directory (C:\WINDOWS\tmp) - works fine
Attempt to run conversion script using tmp file that was uploaded and it doesn't work - run from command line works perfectly fine though
Scenario 2:
File is uploaded to directory I have given IIS_IUSRS full control of (for testing) and file won't upload - yes the directory is spelt correctly (I changed the upload_tmp_dir value in php.ini)
Both the site the javascript that send the XMLHttpRequest to the PHP file, as well as the site the PHP file itself reside on are IIS sites so I assume the script is being run as IIS_IUSRS.
EDIT: Temp file is no longer being created at all for Scenario 1, can't figure out why I am assuming playing with permission messed something up because the code hasn't changed. I've given Modify to IIS_USRS and USERS to try and get it working again but no luck :( although the error log is still writing to the same folder...weird
NOTE: The "tmp_name" value of the $_FILES variable I am sending still has a value of "C:\WINDOWS\Temp\'filename'" but the file is not there
EDIT: Another new development, it appears it is NOT a permissions issue because I can create a temp file via $temp_file = tempnam(sys_get_temp_dir(), 'Test'); however it obviously does not contain the uploaded data so it does not solve my problem
PHP is ignoring the upload_tmp_dir because of one setting on APPLICATION POOLS.
It's not php-cgi.exe nor php.ini or a permissions issue.
Go to the application pool of the website experiencing the issue:
1. right click
2. select advanced settings
3. scroll to LOAD USER PROFILE and set it to FALSE.
that did the trick for me.
This is less of a problem solved and more of a workaround. The issue seems to be something with the
$_FILES['file']['tmp_name'];
When I echo the contents it looks as I expect however no file appears. So rather than taking advantage of that process that happens naturally, I have had to take a manual approach. What I have done is the following:
create a temp file
$temp_file = tempnam(ini_get('upload_tmp_dir'), 'php');
then add the content from the temp file created during the $_POST request. (which some how are in the $_FILES variable even though the file is not when I look in the directory)
file_put_contents($temp_file, file_get_contents($_FILES['file']['tmp_name']));
the I have my temporary file for processing.
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 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 :)