Error in forced download by php

Asked

Viewed 697 times

2

Hello I have the code below to force and rename media files in mp4 via remote URL download with everything the download is coming corrupted as it is not performing the download properly. How can I fix this because the file while downloading is getting 2kbs in size.

$file = 'http://thumb.mais.uol.com.br/15328248.mp4';
$nome = 'novoNome.mp4';
header("Content-Description: File Transfer");
header("Content-Type: video/mp4");
header('Content-Disposition: attachment; filename="' . ($nome) . '";'); 
header('Content-Length: ' . strlen(file_get_contents($file)));
readfile($file); 
  • Dude, I tested your code and the download worked normally, can’t it be something on your network that corrupted the download? does the test with smaller files or other types... in this link says to put ob_clean(); flush(); before readfile, see if it changes something for you....

  • Here only worked with small files need it to work with large files in max up to 300mbs.

1 answer

1


See if the attributes:

memory_limit, post_max_size, upload_max_filesize, max_execution_time

They have the values you want in php.ini

  • ai that ta put everything to 300 Mb and still does not take the maximum file size leaving it corrupted with 2kbs. And in case I’m getting remote URL I’m not uploading this file to my server just need it to take the right size and change the file name directly by header.

  • You modified the memory_limit to how much? Generally this type of error occurs because the server consumes more than 300 MB when a 300 MB download is requested. Dai depends on how much you can increase on your server. But, there were cases that I had to set 1024 MB or 2048 to be able to pass great downloads to the user. (sometimes I just set these values in the PHP page that used the download). Or modify PHP ini, restart APACHE and go quiet.

  • The files do not reach 200mb and memory_limit I put to 300mb.

  • But like I told you, he always consumes more than the file size. And, in this case, I always modified at least the 3 parameters (upload max filesize, post max size and the memory limit). Try putting in a bigger size and see if it goes.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.