Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Something went wrong for processing on server side #6

Open
Andrisetianabrata opened this issue Mar 6, 2024 · 2 comments
Open

Something went wrong for processing on server side #6

Andrisetianabrata opened this issue Mar 6, 2024 · 2 comments

Comments

@Andrisetianabrata
Copy link

how to fix Something went wrong for processing on server side at laravel 10?

image

Routes

<?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/

use App\Http\Controllers\UploadController;

 Route::get('/',[UploadController::class, 'index']);
 Route::post('/crop',[UploadController::class, 'crop'])->name('crop');

Page blade

<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <title>Laravel</title>

        <!-- Fonts -->
        <link rel="preconnect" href="https://fonts.bunny.net">
        <link href="https://fonts.bunny.net/css?family=figtree:400,600&display=swap" rel="stylesheet" />

        <!-- Styles -->
        <link rel="stylesheet" href="{{ asset('/ijaboCropTool.min.css') }}">

    </head>
    <body class="antialiased">
        <input type="file" name="file" id="file">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> 
        <script src="{{ asset('/ijaboCropTool.min.js') }}"></script> 
        <script>
            $('#file').ijaboCropTool({
               preview : '.image-previewer',
               setRatio:1,
               allowedExtensions: ['jpg', 'jpeg','png'],
               buttonsText:['CROP','QUIT'],
               buttonsColor:['#30bf7d','#ee5155', -15],
               processUrl:'{{ route("crop") }}',
               withCSRF:['_token','{{ csrf_token() }}'],
               onSuccess:function(message, element, status){
                  alert(message);
               },
               onError:function(message, element, status){
                 alert(message);
               }
            });
       </script>
    </body>
</html>

UploadController

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\File;
use Intervention\Image\Facades\Image;

class UploadController extends Controller
{
    function index(Request $request)
    {
        return view('welcome');
    }
    public function crop(Request $request)
    {
        $path = 'files/';
        if (!File::exists(public_path($path))) {
            File::makeDirectory(public_path($path), 0777, true);
        }
        $file = $request->file('file');
        $new_image_name = 'UIMG' . date('Ymd') . uniqid() . '.jpg';
        $resize_upload = Image::make($file->path())
            ->fit(250, 250)
            ->save($path . $new_image_name);

        if ($resize_upload) {
            return response()->json(['status' => 1, 'msg' => 'Image has been cropped successfully.', 'name' => $new_image_name]);
        } else {
            return response()->json(['status' => 0, 'msg' => 'Something went wrong, try again later']);
        }
    }
}
@mberecall
Copy link
Owner

how to fix Something went wrong for processing on server side at laravel 10?

image

Routes

<?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "web" middleware group. Make something great!
|
*/

use App\Http\Controllers\UploadController;

 Route::get('/',[UploadController::class, 'index']);
 Route::post('/crop',[UploadController::class, 'crop'])->name('crop');

Page blade

<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <title>Laravel</title>

        <!-- Fonts -->
        <link rel="preconnect" href="https://fonts.bunny.net">
        <link href="https://fonts.bunny.net/css?family=figtree:400,600&display=swap" rel="stylesheet" />

        <!-- Styles -->
        <link rel="stylesheet" href="{{ asset('/ijaboCropTool.min.css') }}">

    </head>
    <body class="antialiased">
        <input type="file" name="file" id="file">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> 
        <script src="{{ asset('/ijaboCropTool.min.js') }}"></script> 
        <script>
            $('#file').ijaboCropTool({
               preview : '.image-previewer',
               setRatio:1,
               allowedExtensions: ['jpg', 'jpeg','png'],
               buttonsText:['CROP','QUIT'],
               buttonsColor:['#30bf7d','#ee5155', -15],
               processUrl:'{{ route("crop") }}',
               withCSRF:['_token','{{ csrf_token() }}'],
               onSuccess:function(message, element, status){
                  alert(message);
               },
               onError:function(message, element, status){
                 alert(message);
               }
            });
       </script>
    </body>
</html>

UploadController

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\File;
use Intervention\Image\Facades\Image;

class UploadController extends Controller
{
    function index(Request $request)
    {
        return view('welcome');
    }
    public function crop(Request $request)
    {
        $path = 'files/';
        if (!File::exists(public_path($path))) {
            File::makeDirectory(public_path($path), 0777, true);
        }
        $file = $request->file('file');
        $new_image_name = 'UIMG' . date('Ymd') . uniqid() . '.jpg';
        $resize_upload = Image::make($file->path())
            ->fit(250, 250)
            ->save($path . $new_image_name);

        if ($resize_upload) {
            return response()->json(['status' => 1, 'msg' => 'Image has been cropped successfully.', 'name' => $new_image_name]);
        } else {
            return response()->json(['status' => 0, 'msg' => 'Something went wrong, try again later']);
        }
    }
}

Check if GD extension is enabled on your server. and then, run "php artisan optimize" command.

@Andrisetianabrata
Copy link
Author

Check if GD extension is enabled on your server. and then, run "php artisan optimize" command.

it's work but the only in new project
my old project still gave the same error
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants