Jump to content

Recommended Posts

Am un script prin care citesc fisierele cu readfile pentru a le oferi spre descarcare. Problema este ca, serverul nu trimite spre anumite browsere, cum ar fi Google Chrome headerul Content-Length am dezactivat compresia gzip din Apache, in .htaccess am setat SetEnv no-gzip dont-vary si nu stiu ce sa mai fac, pentru ca la Network in Chrome tot apare headerul cum ca ar fi activata compresia gzip (am dat restart la apache). Ma chinui de ore bune si nu ii dau deloc de cap. Problema dubioasa este ca pe Firefox trimite Content-Length-ul si nu intelg de ce.

Link to comment
Share on other sites

TU trebuie sa trimiti asta.

    header('Content-Type: application/octet-stream');

header('Content-Disposition: attachment; filename='.basename($file));

header('Content-Transfer-Encoding: binary');

header('Content-Length: ' . filesize($file));

De aici: PHP: readfile - Manual

Am citit mosule peste tot, am testat si aia, am testat-o chiar si acum si nu imi mai arata marimea nici pe Firefox.. Chiar nu mai am idei.

Link to comment
Share on other sites

Poti pune codul?

Sa nu te sperii ca am ajuns la carnatul asta, dar chiar nu mai stiu ce sa ii fac:

ob_end_flush(); // The ob_gzhandler one

header("Status: 200");

header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");

header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');

header("Pragma: hack");

header("Cache-Control: must-revalidate, post-check=0, pre-check=0");

header("Cache-Control: private", false);

header('X-Pad: avoid browser bug');

header("Content-Description: File Transfer");

header("Content-Type: application/force-download");

header("Content-Type: application/download");

header("Content-Type: audio/mpeg");

header("Content-Disposition: attachment; filename=\"".$nume."\"");

header("Content-Transfer-Encoding: binary");

header("Content-Length:".$contentLength);

ob_clean();

flush();

readfile(str_replace(" ", "%20", $url));

ob_end_flush(); // The main one

exit;

Link to comment
Share on other sites

S-ar putea sa gresesc avand in vedere ca pe firefox functioneaza si nici nu cunosc tot codul, dar incearca asa:


ob_end_clean(); // The ob_gzhandler one
header("Status: 200");
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
header("Pragma: hack");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private", false);
header('X-Pad: avoid browser bug');
header("Content-Description: File Transfer");
header("Content-Type: application/force-download");
header("Content-Type: application/download");
header("Content-Type: audio/mpeg");
header("Content-Disposition: attachment; filename=\"".$nume."\"");
header("Content-Transfer-Encoding: binary");
header("Content-Length:".$contentLength);

readfile(str_replace(" ", "%20", $url));
ob_end_flush(); // The main one
exit;

Link to comment
Share on other sites

Pai dupa cum vezi tu in codul ce l-am postat, nu am omis nimic.

esti sigur?

eu vad:

header("Content-Transfer-Encoding: binary");

header("Content-Length:".$contentLength);

nu e niciun spatiu dupa ":", este spatiu in valoarea (tratata ca string, ex. " 4321") detinuta de variabila?

ai testat?

poate asta e motivul pentru care firefox interpreteaza acel spatiu ce lipseste iar celalalte respecta strict rfc

Link to comment
Share on other sites

esti sigur?

eu vad:

nu e niciun spatiu dupa ":", este spatiu in valoarea (tratata ca string, ex. " 4321") detinuta de variabila?

ai testat?

poate asta e motivul pentru care firefox interpreteaza acel spatiu ce lipseste iar celalalte respecta strict rfc

Nu merge mosule, am testat acum, oricum ar fi fost culmea sa fie de la aia. Pur si simplu serverul nu trimite headerul ala, parca e futut in cur, nu stiu ce naiba are.

Link to comment
Share on other sites

@readfile nu-ti poate reda size-ul. Incearca sa setezi size-ul inainte de readfile. Arata-ne unde intializezi variabila de length. Daca preiei content-ul prin read file de pe alt site uita de size deoarece nu pot, mi-am batut si eu capul (explicatia este ca tu nu faci cache la ce trimiti userului prin force download). In cazul in care vei face cache pe server atunci vei avea si length-ul.

Link to comment
Share on other sites

Simplu bre, inainte de readfile pune asta

session_write_close();

Gata, ai headerul acolo :)

'Pare rau, dar nu merge nici asta.

@Zatarra, m?rimea o preiau dup? cum am zis din headerele request-ului cURL, deci nu e acolo problema. Am s?pat cu Dubfix ?i se pare c? e din configura?ia apache-ului, dar acum s? vedem ce nu e ok, pentru c? nu e primul script pe care îl fac, dar nu am mai avut problema asta pân? acum.

Edited by Silviu
Pentru Zatarra
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...