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.
Chmod function is not working in php code
Moderator: General Moderators
- kkrishieee143
- Forum Newbie
- Posts: 1
- Joined: Fri Sep 17, 2010 7:57 am
- mecha_godzilla
- Forum Contributor
- Posts: 375
- Joined: Wed Apr 14, 2010 4:45 pm
- Location: UK
Re: Chmod function is not working in php code
Some notes from the PHP manual for chmod():
HTH,
Mecha Godzilla
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?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.
HTH,
Mecha Godzilla
Re: Chmod function is not working in php code
Playing with a system's chmod is VERY dangerous and this seems a VERY round about way of emailing data to the administrator.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.
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