【问题标题】:Php script that download file not work under ubuntu 14下载文件的php脚本在ubuntu 14下不起作用
【发布时间】:2015-12-28 09:06:20
【问题描述】:

我有一个名为 openFile.php 的文件,其中包含以下数据:

<?php
$file = $_GET['pathFile'];

if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/pdf');
    header('Content-Type: application/octet-stream');
    header('Content-Transfer-Ecoding: binary');
    header('Content-Disposition: attachment; filename='.basename($file).'');
    header('Cache-Control: public');
    readfile($file);
    exit;
}
else
{
   echo("<h1 style='text-align:center;color:red;font-size:bold;'>File ".basename($file)." non trovato !</h1>");
}
?>

我每天在带有 XAMPP 的 Windows 下使用这个脚本并且一切正常,但是我已经用 Ubuntu 14.04 更改了我的服务器,现在当我尝试下载时,我认为浏览器会下载一个没有扩展名且没有内容的文件。

【问题讨论】:

  • 这可能是权限问题。你能检查一下你在ubuntu中给这个文件的权限吗?您可以使用命令:chmod 来更改权限。

标签: php ubuntu download xampp


【解决方案1】:

如果有权限问题,请给予权限:

sudo chmod -R 777 [文件路径]

注意:检查日志文件以查看错误信息

tail -20 /var/log/apache2/error.log
tail -20 /var/log/httpd/error_log

【讨论】:

  • 我尝试执行此命令....现在,如果我上传和下载 png 文件,它可以工作,但如果我上传并尝试下载另一种类型的 ex.pdf,则不起作用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-11-16
  • 2011-09-05
  • 1970-01-01
  • 2012-11-26
  • 2015-08-07
  • 2012-02-04
相关资源
最近更新 更多