【问题标题】:ZipArchive::close(): Failure to create temporary file in AWS EC2 LinuxZipArchive::close():无法在 AWS EC2 Linux 中创建临时文件
【发布时间】:2017-10-06 04:06:50
【问题描述】:

我正在 laravel 5.2 中处理 cron 作业,当我尝试从计划调用控制器函数来创建 excel 工作表时出现错误。但在邮递员中运行良好。

ZipArchive::close(): Failure to create temporary: No such file or directory' in /var/www/html/Expenses/vendor/phpoffice/phpexcel/Classes/PHPExcel/Writer/Excel2007.php:398

zipArchive 的临时文件权限问题?

将 phpexcel 工作表保存到目录 (777) 时出现上述错误。

$excel_path = 'SubmittedSheets/'.$userId.'-'.uniqid().'.xlsx';
$objWriter->save($excel_path);

【问题讨论】:

  • 您配置为 PHP 临时文件夹的文件夹是否真的存在?如果是这样,您的脚本是否可以访问它? (请记住,cron 作业可能以与 Web 访问不同的用户身份运行)
  • @hassan - 我看到了这个解决方案,但不清楚。如果你知道,请解释一下。
  • @MarkBaker - 我没有配置任何临时文件夹。我给出的路径是 PHPExcel。
  • PHP 临时文件夹的配置与 PHPExcel 无关;它是您的 PHP/OS 配置的一部分。您可以使用 PHP 的 sys_get_temp_dir() 函数找到它的设置

标签: php linux amazon-web-services amazon-ec2 phpexcel


【解决方案1】:

需要绝对路径才能在 AWS Ec2 Linux for PHPExcel 中保存 excel 文件。

$excel_path = '/var/www/html/MyProject/public/SubmittedSheets/'.$userId.'-'.uniqid().'.xlsx';
$objWriter->save($excel_path); 

【讨论】:

  • 我有同样的错误,但解决方案不起作用:(,即使我使用过 -- $objWriter->save('/var/www/yebesis/public_html/files/caglar.orhan/test.xlsx ');
  • @caglaror - 这也是由于磁盘空间不足,检查您的 AWS 可用空间,点击 df -hdu -sh。请让我知道错误信息。
  • 不,它有很多空间:(
  • 我不在 AWS Ec2 上,但我在 Azure 上配置的 Centos7 上遇到了同样的问题。 sys_temp_dir 为空。我不得不去编辑 php.in 来设置 tmp 目录路径来修复这个错误。
【解决方案2】:

我在我的 Mac OS 系统上通过简单地取消注释来解决它

;sys_temp_dir = "/tmp"

php.ini中,即改为

sys_temp_dir = "/tmp"

应放置临时文件的目录。 默认为系统默认值(参见 sys_get_temp_dir)

不确定它尝试使用哪个目录作为默认目录,可能是/var/tmp,我的 Homebrew PHP 安装似乎没有写入权限。

【讨论】:

    【解决方案3】:

    我尝试了很多东西,也花了很多时间。 Ubuntu + Vesta + Nginx + Apache 的解决方案在文件中:

    :/home/admin/conf/web/your-domain.com.apache2.ssl.conf
    

    像我的例子一样设置 tmp 文件夹:

    <Directory /home/admin/web/your-domain.com/public_html>
        AllowOverride All
        SSLRequireSSL
        Options +Includes -Indexes +ExecCGI
        php_admin_value open_basedir 
        /home/admin/web/your-domain.com/public_html:/tmp
        php_admin_value upload_tmp_dir /tmp
        php_admin_value session.save_path /tmp
    </Directory>
    

    example image

    别忘了重启apache服务

    【讨论】:

      猜你喜欢
      • 2017-04-15
      • 2018-11-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-03
      • 1970-01-01
      • 2016-06-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多