duanmei1350 2015-10-26 21:48
浏览 32
已采纳

Laravel 5在使用pathinfo()和不可写目录的共享主机上发布了问题

I managed to get my laravel app to work on shared hosting.

Following this tutorial, I moved the app files into a /reddit/ directory outside /public_html/ and the files inside /public/ into /public_html/

All works well until I try submitting a post, then I get this error

Can't write image data to path (/images/Q4vQitDu.)

This is the chunk of code it is referring to

$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)];

As you can see, it is generating the image name with the dot but not the {$extension} - I have no idea why as it is working locally.

It also says the /images/ is unwritable, but it is. It exists in /public_html/images/ and permissions are set to 777

UPDATE

I fixed the permission issue by changing the /images/ url to the full server url /home/maghnatis/public_html/images/

But images are still being saved without their extension.

This is index.php in /public_html/

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

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

It is loading files from /reddit/ dir outside /public_html/

I am on PHP 5.5 and these are the loaded modules

enter image description here

  • 写回答

1条回答 默认 最新

  • doufan9290 2015-10-26 22:22
    关注

    Fixed.

    instead of /images/

    I used the full server path /home/maghnatis/public_html/images/

    And I checked for extension name before sending it to the database

    $orig = pathinfo($info->image, PATHINFO_EXTENSION);
    $qmark = str_contains($orig, '?');
    if($qmark == false) {
        $extension = $orig;
    } else {
        $extension = substr($orig, 0, strpos($orig, '?'));
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog