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 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测