【问题标题】:Laravel 5 issues on shared hosting with pathinfo() and unwritable directoryLaravel 5 关于使用 pathinfo() 和不可写目录的共享主机问题
【发布时间】:2015-10-26 21:48:37
【问题描述】:

我设法让我的 laravel 应用在共享主机上运行。

按照这个tutorial,我将应用程序文件移动到/public_html/之外的/reddit/目录,并将/public/内的文件移动到/public_html/

在我尝试提交帖子之前一切正常,然后我收到此错误

无法将图像数据写入路径 (/images/Q4vQitDu.)

这是它所指的代码块

$orig = pathinfo($info->image, PATHINFO_EXTENSION);
$extension = substr($orig, 0, strpos($orig, '?'));

$newName = '/images/' . str_random(8) . ".{$extension}";

if (File::exists($newName)) {
    $imageToken = substr(sha1(mt_rand()), 0, 5);
    $newName = '/images/' . str_random(8) . '-' . $imageToken . ".{$extension}";
}

$image = Image::make($info->image)->fit(70, 70)->save($newName);
$embed_data = ['text' => $info->description, 'image' => basename($newName)];

如您所见,它生成的是带点的图像名称,而不是 {$extension} - 我不知道为什么,因为它在本地工作。

它还说/images/ 是不可写的,但确实如此。存在于/public_html/images/,权限设置为777

更新

我通过将 /images/ url 更改为完整的服务器 url /home/maghnatis/public_html/images/ 修复了权限问题

但图像仍会在没有扩展名的情况下保存。

这是/public_html/中的index.php

require __DIR__.'/../reddit/bootstrap/autoload.php';

$app = require_once __DIR__.'/../reddit/bootstrap/app.php';

它正在从/public_html/ 外部的/reddit/ 目录加载文件

我使用的是 PHP 5.5,这些是已加载的模块

【问题讨论】:

    标签: php apache laravel laravel-5


    【解决方案1】:

    固定。

    而不是/images/

    我使用了完整的服务器路径/home/maghnatis/public_html/images/

    我在将扩展名发送到数据库之前检查了扩展名

    $orig = pathinfo($info->image, PATHINFO_EXTENSION);
    $qmark = str_contains($orig, '?');
    if($qmark == false) {
        $extension = $orig;
    } else {
        $extension = substr($orig, 0, strpos($orig, '?'));
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-21
      • 1970-01-01
      • 2015-11-10
      • 1970-01-01
      • 2015-10-04
      • 1970-01-01
      • 1970-01-01
      • 2019-06-27
      相关资源
      最近更新 更多