Page 1 of 1

Chmod function is not working in php code

Posted: Fri Sep 17, 2010 9:58 am
by kkrishieee143
HI Friends,

Goal:
My website has forms and when the user fills and submits the form with the data.Then the data collected from the forms are getting saved in a new file "data.html". This file is created dynamically on fly and then we are creating a pdf file (html - > pdf) and this pdf generated will be attached to an email which will be sent to administrator or owner of the website.

Problem:
We are able to create the "data.html" and for generating the pdf file we need to retrieve the data from the "data.html". For this "data.html" need the 777 permissions.
For assigning the permissions, we are using chmod function.
Problem is that the chmod function is not working.
Is there any other alternative to tackle this issue.


(Note: Chmod function is working in shared hosted server but not working in dedicated hosted servers. Tried in many servers.)


Thanks,
Saikrishna.

Re: Chmod function is not working in php code

Posted: Sat Sep 18, 2010 5:55 pm
by mecha_godzilla
Some notes from the PHP manual for chmod():
The current user is the user under which PHP runs. It is probably not the same user you use for normal shell or FTP access. The mode can be changed only by user who owns the file on most systems.

When safe mode is enabled, PHP checks whether the files or directories you are about to operate on have the same UID (owner) as the script that is being executed. In addition, you cannot set the SUID, SGID and sticky bits.
Based on that information, checking whether safe mode has been enabled would make sense. Also, have you tried using shell_exec() to manually set the permissions?

HTH,

Mecha Godzilla

Re: Chmod function is not working in php code

Posted: Sat Sep 18, 2010 8:11 pm
by Weiry
kkrishieee143 wrote:HI Friends,

Goal:
My website has forms and when the user fills and submits the form with the data.Then the data collected from the forms are getting saved in a new file "data.html". This file is created dynamically on fly and then we are creating a pdf file (html - > pdf) and this pdf generated will be attached to an email which will be sent to administrator or owner of the website.

Problem:
We are able to create the "data.html" and for generating the pdf file we need to retrieve the data from the "data.html". For this "data.html" need the 777 permissions.
For assigning the permissions, we are using chmod function.
Problem is that the chmod function is not working.
Is there any other alternative to tackle this issue.


(Note: Chmod function is working in shared hosted server but not working in dedicated hosted servers. Tried in many servers.)


Thanks,
Saikrishna.
Playing with a system's chmod is VERY dangerous and this seems a VERY round about way of emailing data to the administrator.
You should really never use anything above 644 (-rw-r--r--) for files let alone 777, otherwise you can open yourself up to script kiddy exploits. And judging by what you are doing so far, id say your using fopen() which also has its problems with exploits.

You should try to use PHP's inbuild PDF functions or use a class like FPDF

Here's a quick example of using FPDF for emailing a PDF to a user:
Create And Email PDF File 'On The Fly' With PHP