Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 2 of 2 FirstFirst 12
Results 16 to 22 of 22
  1. #16
    Regular Coder
    Join Date
    Apr 2008
    Location
    Manila, Philippines
    Posts
    263
    Thanks
    3
    Thanked 12 Times in 12 Posts
    Quote Originally Posted by tangoforce View Post
    Yet the message shows a file of 493MB - the op states its a 500MB file.

    There is however (on that note you pointed out) a call to ob_clean.

    @jhaycutexp Why are you using ob_clean? -I don't see a call to ob_start anywhere.
    it was suggest in the PHP manual..

    I dont know..

    I am currently learning now.. why.. I was asked to make it work..

    and it will be easy... if it were just html.. and if it were just chrome and firefox i have to deal with..

    but working with crossbrowsers is a headache..

    in HTML5 I can go with an attribute tag download.. it works with firefox and chrome.. but dont work on IE and safari.. which is why I am forced use PHP.. hehehe

  2. #17
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,036
    Thanks
    2
    Thanked 316 Times in 308 Posts
    If output buffering is turned on in your php.ini or you are using a php debugger (some use output buffering to capture the debugging output) you can have a few levels of output buffering in effect at the time you are running the readfile() statement.

    I would be interested in seeing what echoing ob_get_level() shows.

    If it's not a zero, you will need to call ob_end_clean() enough times before the readfile() statement to turn off each level of buffering so that the readfile() doesn't stick the file contents into an output buffer.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  3. #18
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    ob_clean is in the wrong place now that I think of it. That has the purpose of scrubbing the buffers out and dumping the output (not sending it). The problem is what happens when it exceeds the size, and that I don't have an immediate answer for.
    Technically you can keep it. But it has to go before the readfile; its purpose would be to scrub any output but it will only work if ob_start has been initiated or output buffering is enabled at a config level.

    The issue you are seeing here is that the output buffering is likely what's exhausting the memory. If you use looped reads, that'd be fine as you can dump -> flush as much as you want. But the readfile will export directly to the output stream and with output buffering enabled it will be limited to the output buffer size.

    Immediately before the header() calls, add ob_end_clean();, and remove the calls to the flush and clean after the readfile. Try that.

    Edit:
    A bit late on the ball :P
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  4. #19
    Regular Coder
    Join Date
    Apr 2008
    Location
    Manila, Philippines
    Posts
    263
    Thanks
    3
    Thanked 12 Times in 12 Posts
    Quote Originally Posted by tangoforce View Post
    Using http://www.convert-me.com I input the bytes from your error message. You have 128MB memory to play with so yes, any smaller files of 1-10MB should be ok.



    What sort of server are you on? Is it shared hosting or a dedicated / VPS server? (If you don't know, it will almost certainly be shared - you'd know if you had a dedi or VPS).



    It's possible that the script is using ini_set() to change the memory limit of your php. If you're on a shared host you must do this with caution - lots of caution because at some point you will overwhelm the server and your host will shut you down. If you're on a dedi or vps you'd be ok!
    Its most likely a shared one... cause as i see in them.. its a virtual machine..

    if its not directly a memory issue.. what could it be? I have to undertand this.. reading is really not my favorite when it goes like this..

  5. #20
    Regular Coder
    Join Date
    Apr 2008
    Location
    Manila, Philippines
    Posts
    263
    Thanks
    3
    Thanked 12 Times in 12 Posts
    hi everyone..

    I'll post test and errors later..

    so everyone can make any analysis

    Thanks

  6. #21
    New Coder
    Join Date
    Sep 2013
    Posts
    41
    Thanks
    0
    Thanked 1 Time in 1 Post
    Try out with the below example code, it has worked fine for me:

    <?php
    // Fetch the file info.
    $filePath = '/path/to/file/on/disk.jpg';

    if(file_exists($filePath)) {
    $fileName = basename($filePath);
    $fileSize = filesize($filePath);

    // Output headers.
    header("Cache-Control: private");
    header("Content-Type: application/stream");
    header("Content-Length: ".$fileSize);
    header("Content-Disposition: attachment; filename=".$fileName);

    // Output file.
    readfile ($filePath);
    exit();
    }
    else {
    die('The provided file path is not valid.');
    }
    ?>

    Hope this helps.

  7. #22
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,322
    Thanks
    60
    Thanked 525 Times in 512 Posts
    Blog Entries
    4
    Quote Originally Posted by jhaycutexp View Post
    Its most likely a shared one... cause as i see in them.. its a virtual machine..
    That makes no sense. It's shared hosting but it's also a virtual machine?

    Quote Originally Posted by jhaycutexp View Post
    if its not directly a memory issue.. what could it be? I have to undertand this.. reading is really not my favorite when it goes like this..
    It IS a memory issue. That is exactly what your error message is telling you - the memory has been exausted at 128MB and you're trying to assign 493MB.

    The cause of this is your output buffering. What you are doing is reading the file in but instead of it being served straight to the clients browser, php is temporarily trying to store it in the memory because youu are using output buffering. With a limit of 128MB and a 493MB file, it's naturally going to run out of memory.

    Remove the output buffering.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!


 
Page 2 of 2 FirstFirst 12

Posting Permissions

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