Results 1 to 9 of 9

Thread: problem in opening a file on server

  1. #1
    Join Date
    Feb 2009
    Posts
    27
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Question problem in opening a file on server

    Hello all ,

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

    Code:
    $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.
    Last edited by MSK7; 12-28-2009 at 06:13 AM.

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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.
    Last edited by djr33; 12-26-2009 at 10:34 PM.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Feb 2009
    Posts
    27
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Arrow Reply

    Hello djr33,

    Thanks for your precious reply.

    on using the code
    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.
    Last edited by MSK7; 12-28-2009 at 06:14 AM.

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Feb 2009
    Posts
    27
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Arrow Reply

    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 -
    Code:
    $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.
    Last edited by MSK7; 12-28-2009 at 08:31 AM.

  6. #6
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  7. #7
    Join Date
    Feb 2009
    Posts
    27
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Arrow reply

    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 -
    Code:
    $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.

  8. #8
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  9. The Following User Says Thank You to djr33 For This Useful Post:

    MSK7 (12-28-2009)

  10. #9
    Join Date
    Feb 2009
    Posts
    27
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Smile reply

    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •