Проблема с загрузкой файлов на сервер/PHP
это мой код, чтобы заставить скачивание:
<?php
ftp_get($conn, $local_file , $server_file, FTP_BINARY);
header('Content-Disposition: attachment; filename="' . $local_file . '"');
readfile($local_file);
ftp_close($conn);
?>
проблема В том, что файл идет пустой. Есть что-то в Apache, который мне нужно включить, потому что код идентичен в документации php.
1
1 answers
Попытайтесь использовать следующий скрипт,
<?php
set_time_limit(0); // Define o tempo máximo de execução em 0 para as conexões lentas
$arquivoLocal = '/pasta/do/arquivo.zip'; // caminho absoluto do arquivo
// Verifica se o arquivo não existe
if (!file_exists($arquivoLocal)) {
echo "Arquivo não encontrado.";
exit;
}
$novoNome = 'novoNome.zip'; // Definimos o novo nome do arquivo
header('Content-Description: File Transfer');
header('Content-Disposition: attachment; filename="'.$novoNome.'"');
header('Content-Type: application/octet-stream');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($arquivoLocal));
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Expires: 0');
readfile($arquivoLocal);
2
Author: Guhh, 2016-10-28 18:34:35