SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Oct 2009
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    header redirect to file, wait, then unlink same file. why does it run backwards???

    simple enough, right? I run this:

    // copy file to stage folder
    copy($pathtofile."/".$nameandext, $_SERVER['DOCUMENT_ROOT']."/files/box/stage/".$nameandext);

    header("location: /files/box/stage/"."$nameandext"); // send copy to browser
    usleep(2000000); // wait
    unlink($_SERVER['DOCUMENT_ROOT']."/files/box/stage/".$nameandext); // destroy copy in stage folder
    die();

    and I get this: wait, delete, 404! (or is it delete, wait, 404!) I trust copy is happening, because...

    all works great without wait and delete
    - but I need to destroy copy immediately!

    WTF... any ideas why this is happening please!!

  2. #2
    SitePoint Enthusiast
    Join Date
    Aug 2010
    Location
    Perundurai, Tamilnadu, India
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    header("location: /files/box/stage/"."$nameandext"); // send copy to browser 
    header function will just send header information to browser, it is not sending complete file to browser.

    Try to use the below code, surely it will work and i have tested it.

    PHP Code:
    header('Content-type: text/plain'); // change this content type based on your file extension
    header('Content-Disposition: attachment; filename="'.$nameandext.'"');

    readfile($nameandext);

    ob_end_flush();

    unlink($nameandext); 

  3. #3
    SitePoint Zealot
    Join Date
    Oct 2009
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi Tamil!

    yes, that would explain things...

    it's late here and will have a go at your suggestion tomorrow.

    much thanks for your time and expertise Tamil !!

  4. #4
    SitePoint Zealot
    Join Date
    Oct 2009
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well getting pretty close. Tamil's suggested code below working EXCEPT no image presented. just an empty box of proper size with the little X in the corner...

    header('Content-type: image/jpeg'); // change this content type based on your file ext
    header('Content-Disposition: inline; filename="'.$newpath.$nameandext.'"');
    readfile($newpath.$nameandext);
    ob_end_flush();
    unlink($newpath.$nameandext);

    now I'm going in circles. the problem above is why I switched from non-working readfile(), fopen(), fpassthru(), to the WORKING header(location) redirect !!!

    why is that image getting lost???
    OR is there some way to force completion of header(location) redirect, then unlink the same file ???
    any thoughts at all PLEASE !!


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
  •