Php problem pissing me off

Discussion in 'PHP' started by logylaps, Oct 3, 2008.

  1. #1
    Hello,
    I have the following script, which should work 100% in theory, but it just dosnt.

    	
    if (file_exists($fileUrl)) {
    	$fileSize = (string)(filesize($fileUrl));
    	header ("Content-Type: video/avi");
    	header ("Content-Length: ".$fileSize);
    	header ('Content-Disposition: attachment; filename="Psych-Season'.$season.'Episode'.$episode.'.avi"');
    	readfile($fileUrl);
    	exit();
    }
    
    PHP:
    I works, and sends the file to the user, but there is no progress bar when downloading. This should have been fixed by
    header ("Content-Length: ".$fileSize); 
    PHP:
    but it isnt.

    Please help me out
     
    logylaps, Oct 3, 2008 IP
  2. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    #2
    can u print the value of filesize if its printing the values correctly


    try this alternative
    (file_exists($fileUrl)) {
    header("Content-type: application/octet-stream\n");
    header("Content-disposition: attachment; filename=\"".$fileUrl."\"\n");
    header("Content-transfer-encoding: binary\n");
    header("Content-length: ".filesize($fileUrl)."\n");

    $fp = fopen($fileUrl, "rb");
    while(!feof($fp)) {
    $buffer = fread($fp, 4096);
    print $buffer;
    }
    fclose($fp);
     
    kmap, Oct 4, 2008 IP
  3. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    #3
    probably u r not using \n thats why ur code is not working

    Regards

    Alex
     
    kmap, Oct 4, 2008 IP
  4. logylaps

    logylaps Active Member

    Messages:
    761
    Likes Received:
    25
    Best Answers:
    0
    Trophy Points:
    85
    #4
    Here is what I get when I run
    die($fileSize);
    PHP:
    365697024

    Tried... same problem

    Tried adding \n to each header, didnt help.

    I was searching for this online and came upon this:
    Source: http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.4

    I have no idea what it means, but it does mention ignoring the content-length, so im assuming it is relevant. Can you shed any light on this?
     
    logylaps, Oct 4, 2008 IP