PDA

View Full Version : problem in opening a file on server



MSK7
12-26-2009, 11:25 AM
Hello all ,

I am creating a word file named salaryslip using php with fopen().



$f=fopen("NewSalarySlip/SalarySlip_$employid.doc","w") or die("Can't open file");


onrunning this above code on localhost a new word file salaryslip is creating well.

But on running it on Server , error msg "Can't open file" is displayed .


Please help me to create that new word file successfully on Server also .

any suggestions will be appreciated.


Thanks & regards.

djr33
12-26-2009, 10:24 PM
try:
'NewSalarySlip/SalarySlip_'.$employid.'.doc'

If that doesn't work, then there is probably an error with $employid's value-- try echoing it to check.
Or you may have an error with permissions to write files on the server.

"w+" may be better than "w"-- that allows you to read and write, not just write. But that may be irrelevant here.

MSK7
12-28-2009, 06:07 AM
Hello djr33,

Thanks for your precious reply.

on using the code


try:
'NewSalarySlip/SalarySlip_'.$employid.'.doc'


& on echoing $employid's value, & also using 'w+'

on Localhost the word file is creating & writing successfully & also echoing the value of empid on the page.

But again on running this on Server message "Can't open file" is displaying.

Please suggest more about "having an error with permissions to open & write files on the server".


Please kindly help more regarding these.


Thanks.

djr33
12-28-2009, 06:43 AM
I see. Well, there are three possibilities:

1. The file could exist on the server already. Then it may not let you overwrite it: you can use chmod (in php, maybe, or through your ftp program) to change it to "777" or a similar setting to allow this. If the file does not exist, this is not the problem, but it could be the directory-- if you don't have privileges to modify the directory, then you probably can't create files in it. Again, try chmod.

2. PHP may not be setup to modify files on the server. Check php.ini (and maybe other server configurations) to see if you can change a setting.

3. Your host may not allow php to modify files. There might be nothing you can do. If you do have control of the server, you may be able to change something.

MSK7
12-28-2009, 07:48 AM
Hello djr33,

I uploaded manually a blank word file called salaryslip.doc for test in that folder.

Then on manually setting chmod 777 through ftp, for this word file

& when i use to open that uploaded word file using -


$f=fopen("NewSalarySlip/SalarySlip.doc","w+") or die("Can't open file");


it is reading & writing on server well.

But i would like that when i run that code a word file with empid to be automatically created & read,write can be performed on it.

how chmod 777 can be adjusted automatically for all word files for create,read, & write .

Thanks.

djr33
12-28-2009, 08:25 AM
Then it appears that you cannot create files in that directory, or on your server. See options 2 & 3 above. I am not sure about more details than that, unfortunately.

Also, try other modes than "w"-- try them all, even. See if any happen to work better on your server.
http://www.php.net/manual/en/function.fopen.php

MSK7
12-28-2009, 08:32 AM
Hello djr33,

I uploaded manually a blank word file called salaryslip.doc for test in that folder.

Then on manually setting chmod 777 through ftp, for this word file

& when i use to open that uploaded word file using -


$f=fopen("NewSalarySlip/SalarySlip.doc","w+") or die("Can't open file");


it is reading & writing on server well.

But i would like that when i run that code a word file with empid to be automatically created & read,write can be performed on it.

how chmod 777 can be adjusted to be set automatically for all word files to create, read, & write .

Thanks.

djr33
12-28-2009, 08:53 AM
This is based on server settings, or possibly the chmod settings of the folder that contains this script and the files you are creating.
This is not an error in the php code. This is a problem with the server, and I'm not sure how you'd fix it. That really depends on a lot of variables, like what operating system, server software, and how much access you have.

MSK7
12-28-2009, 01:37 PM
Hello djr33,

Thanks for your precious support and guidance regarding my problem.

finally your guidance solved the problem.

On changing the chmod settings of the folder NewSalarySlip that contains

that script to 777, it finally created the word file on the Server also.


Hope to get your precious guidance in future also.



Thanks & Regards.