1

I try to use Intervention for resize a photo added by the user in a form :

if(!empty($_POST))
{
$con = new \App\Controller\CreateController();

if($con->create(['name' => $_POST['title'], 'content' => $_POST['content'], 'users_id' => $_SESSION['auth']->id]))
{
    $postid = App::getInstance()->getDB()->lastInsertId();
    if($con->media(['media_name' => $_FILES['image']['name'], 'posts_id' => $postid]) && $con->thumbs($_FILES['image']['name']))
    {
    ?>

    <div class="alert-success">Post Created !</div>
<?php
header('refresh:2;url= ../public/admin.php?p=home');
    }
}
}

The "create" function save the form information in my DB , the function "media" save the image to my DB and the "thumbs" function is supposed to resize and send the image to my thumbs directory using Intervention.

However, Intervention do not accept "$_FILES['image']['name']" parameter.

This is my function thumbs :

 public function thumbs($image){

    $manager = new ImageManager();
    $manager->make('../public/'.$image)
        ->fit(400,250)
        ->save('../public/images/thumbs/' .pathinfo($image, PATHINFO_FILENAME) . '.jpg');
    return true;
}

Someone can help me?

1 Answers1

0

Intervention needs the full path to the file on the server in order to read it.

The path to the download can be accessed with $_FILES['image']['tmp_name'].

$_FILES['image']['name'] is just the filename client side.

Very similar to this question: Getting complete PATH of uploaded file - PHP

Community
  • 1
  • 1
Kaktus
  • 153
  • 4
  • 23