Laravel 5 issues on shared hosting with pathinfo() and unwritable directory

Halnex

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

Halnex

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, '?'));
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Shared hosting: WordPress/laravel 5

Deploying Laravel on a shared hosting sub-directory

Laravel 5 – Clear Cache in Shared Hosting Server

How to Deploy Laravel 5 on shared cPanel hosting

Laravel on shared hosting with Subdomain

htaccess with Laravel on shared hosting

how to run laravel 5 in shared hosting without composer?

Deploy Laravel 5 using only FTP in a shared hosting

Laravel 5 on shared hosting - wrong public_path()

Reloading .env variables without restarting server (Laravel 5, shared hosting)

Laravel 8 project deploy to shared hosting - security issues and public_html folder

Laravel and shared hosting CURL not working

Sending mail with Laravel on shared hosting

Deploying Laravel 5.4 to Shared Hosting

Laravel deployment shared hosting subdomain

Laravel website 'uploaded on shared hosting' is showing directory structure instead of my specified web routes

Set root directory on shared hosting for multiple projects

Wcf service in virtual directory on shared hosting

How can I update my composer in the godaddy shared hosting developed with the laravel 5

Shared Hosting Laravel 8 Hosting problem: Symlink is not working

Hosting two different applications running on Laravel 4 on shared hosting

Why new installed laravel not work on shared hosting?

Laravel, Using a cPanel shared hosting if possible?

Laravel | Shared hosting routes not working properly

Displaying laravel stored images on shared hosting

Laravel schedule job on cpanel shared hosting not working

Laravel project with bitbucket pipeline on shared hosting

Laravel 4.2 support for PHP 5.3 on shared hosting

Error 404 in a shared hosting in Laravel 8