SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot DocDave's Avatar
    Join Date
    Sep 2004
    Location
    Milwaukee, WI, USA
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    creating a file with 'fopen'

    I am using 'fopen' to create an text file as part of a flat-file db, or write to the file if it already exists. My problem is if the file is not there and 'fopen' is used to create it the file becomes 'locked'. I am not able to delete, or modify the file, not even if I FTP in. CHMOD doesn't work either.

    Here is the code I am using:
    PHP Code:
    $datafile fopen("somefile.txt","a+");
    fwrite($datafile$datatext);
    fclose($datafile); 
    Why am I not able to Delete or CHMOD this file using PHP or FTP?

    I am stuck here, any help would be appreciated.
    .:Blog:.

  2. #2
    With More ! for your $ maxor's Avatar
    Join Date
    Feb 2004
    Location
    Scottsdale, Arizona
    Posts
    909
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you tried
    PHP Code:
    $datafile fopen("somefile.txt""x+"); 
    Quote Originally Posted by PHP manual on fopen(x+)
    Create and open for reading and writing; place the file pointer at the beginning of the file. If the file already exists, the fopen() call will fail by returning FALSE and generating an error of level E_WARNING. If the file does not exist, attempt to create it. This is equivalent to specifying O_EXCL|O_CREAT flags for the underlying open(2) system call. This option is supported in PHP 4.3.2 and later, and only works for local files.

  3. #3
    SitePoint Zealot DocDave's Avatar
    Join Date
    Sep 2004
    Location
    Milwaukee, WI, USA
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried using 'x+' and it causes the same result.
    Is it possible there is some kind of setting on my server that is causing me to not be able to remove these files?
    It seems no matter what I do it will not allow me to delete the text, html, etc files I create, but it does allow me to delete the .jpg files I create.

    I am at a loss.
    Last edited by DocDave; Nov 30, 2004 at 10:49.
    .:Blog:.

  4. #4
    SitePoint Member
    Join Date
    Nov 2004
    Location
    me
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sounds like a problem on Operating-System level. I guess the user that runs the PHP script (via http) is not the same as your ftp user. Do you have shell access to the server? If it runs Unix, can you try "ls -l"?

    best regards

    Sam

  5. #5
    Prolific Blogger silver trophy Technosailor's Avatar
    Join Date
    Jun 2001
    Location
    Before These Crowded Streets
    Posts
    9,446
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can't modify it or change it because it's owned by apache (or nobody), not you. That's the nature of the game.

    If you are using PHP 5, you might look at file_put_contents() as well.

    Aaron
    Aaron Brazell
    Technosailor



  6. #6
    SitePoint Zealot DocDave's Avatar
    Join Date
    Sep 2004
    Location
    Milwaukee, WI, USA
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks everyone for the info.
    I ended up going through the site control panel to delete the folders with these 'locked' files. So at least I got them all cleaned up.
    Unfortunately this does not solve the problem of being able to delete these files remotely. It's back to the drawing board. I will have to find another way to catalog my photos.
    Thanks again for the help.
    .:Blog:.


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
  •