question about unlink

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • datactrl
    New Member
    • Jul 2008
    • 51

    question about unlink

    I try to read a file and send the whole content out then delete that file. When I did as the following, seems the content didn't "print" properly which cuase an error on browser. If I remove "unlink", it works fine. It could be a timing problem. Is there any way to fix it. Thank you in advance!

    Code:
    $rpt_content = file_get_contents("{$_POST['rptpath']}\\output\\$ar[0]");
    print($rpt_content);
    unlink("{$_POST['rptpath']}\\$ar[0]"));
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    You may not have posted all your code but
    you haven't closed the file before unlink()

    Comment

    • Ciary
      Recognized Expert New Member
      • Apr 2009
      • 247

      #3
      isnt this a better way?

      Code:
      $id = fopen("foo/bar.txt",r);
      $mydata = fread($id);
      fclose($id, filesize("foo/bar.txt"));
      unlink("foo/bar.txt");
      print $mydata;
      also, seems to me like your reading another file then you're deleting.

      Comment

      • Amzul
        New Member
        • Oct 2007
        • 130

        #4
        Originally posted by Ciary
        isnt this a better way?

        Code:
        $id = fopen("foo/bar.txt",r);
        $mydata = fread($id);
        fclose($id, filesize("foo/bar.txt"));
        unlink("foo/bar.txt");
        print $mydata;
        also, seems to me like your reading another file then you're deleting.
        not a better way!

        $mydata = fread($id,files ize('foo/bar.txt'));
        fclose ($id);

        file_get_conten ts do that for you faster

        Comment

        • Ciary
          Recognized Expert New Member
          • Apr 2009
          • 247

          #5
          ok, but still: isnt he unlinking the wrong file? the first one is in the map output while the one he's deleting isn't.

          Comment

          • Markus
            Recognized Expert Expert
            • Jun 2007
            • 6092

            #6
            It would be helpful to know the error. :)

            - mark.

            Comment

            • Amzul
              New Member
              • Oct 2007
              • 130

              #7
              Originally posted by datactrl
              I try to read a file and send the whole content out then delete that file. When I did as the following, seems the content didn't "print" properly which cuase an error on browser. If I remove "unlink", it works fine. It could be a timing problem. Is there any way to fix it. Thank you in advance!

              Code:
              $rpt_content = file_get_contents("{$_POST['rptpath']}\\output\\$ar[0]");
              print($rpt_content);
              unlink("{$_POST['rptpath']}\\$ar[0]"));

              whats with the \\output\\ and {} ??
              is that a template file?
              and you should just unlink the $rpt_content
              or you want to delete the file out of the HD
              if this is the case make sure you have the right permissions

              knowing the error will be good

              Comment

              • datactrl
                New Member
                • Jul 2008
                • 51

                #8
                Thank you, everybody. Now it works. The problem is permissions.

                Comment

                Working...