Ошибка при загрузке изображений с использованием jaxa и phpand. - PullRequest
0 голосов
/ 24 апреля 2019

Я использую библиотеку интервенций для преобразования изображений моего веб-сайта в формат изображений webp, и на моем локальном хосте все работает без проблем, но когда я попробовал это на своем живом сервере своего веб-сайта, я получил ошибку, и изображение не удалось загрузить является частью кода PHP, который я использую для загрузки изображений.

// include the database file
require APP_ROOT."/functions/dbh.php";
require  APP_ROOT . '/vendor/autoload.php';
// import the Intervention Image Manager Class
use Intervention\Image\ImageManagerStatic as Image;
$userId = $_SESSION['id'];
$errors = array();
$success = array();
if (isset($_FILES['profileImg']) && !empty($_FILES['profileImg']['name'])) {
    $img = $_FILES['profileImg'];
    $getExt = array("jpg","png","jpeg","gif","jpeg 2000","webp");
  $imageName = strtolower($_FILES['profileImg']['name']);
    $imageNameTmp = strtolower($_FILES['profileImg']['tmp_name']);
    $dividImg = explode('.', $imageName);
    $getImgExt = end($dividImg);
    // check if the file uploaded is an image
    if (!in_array($getImgExt, $getExt)) {
        $errors[] = "Only Those Image Ext Allowed : " . implode(', ', $getExt);
    }else{
            $fileName = $_FILES['profileImg']['name'];
            $fileTmp  = $_FILES['profileImg']['tmp_name'];
            $fileSize = $_FILES['profileImg']['size'];
            $imgError = $_FILES['profileImg']['error'];
            $fileType = $_FILES['profileImg']['type'];
            if ($imgError !== 0) {
                $errors[] = "Oops! Sorry There was an error uploading your image please try again later";
            }else{
            // configure with favored image driver (gd by default)
            Image::configure(array('driver' => 'gd'));
           // set the image width and height for the image
          $newImgName     = "profile" . $userId . ".webp";
          $newImgName2     = "profile" . $userId . "-small.webp";
          $imgDestination = "../profile_image/" . $newImgName;
          $imgDestination2 = "../profile_image/" . $newImgName2;
          $saveProfileImg = Image::make($imageNameTmp)->resize(120, 90)->save($imgDestination);
          $saveProfileImg2 = Image::make($imageNameTmp)->resize(77, 40)->save($imgDestination2);

А это код jquery ajax

// submit a new proile image to the database using ajax
            $("#profileImgForm").on('submit', function(event){
                event.preventDefault();
                $("#loader-icon").removeClass("d-none");
                $.ajax({
                    method: "POST",
                    target:   '#targetLayer', 
                    data: new FormData(this),
                    contentType: false,
                    cache: false,
                    processData:false,
                    url:"<?php echo BASE_URL;?>/profile/add_avatar.php?id=<?php echo $_SESSION['id']; ?>",
                    success:function(data){
                        getAvatar();
                        $("#profileImgError").html(data);
                        $('#loader-icon').addClass("d-none");
                    }

                })
            });

И эта ошибка появляется, когда я могу показать ошибки на моем сервере

Uncaught Intervention\Image\Exception\NotReadableException: Image source not readable On Line 345

эта часть вмешательства состоит в том, чтобы решить проблему

    public function init($data)

{
    $this->data = $data;

    switch (true) {

        case $this->isGdResource():
            return $this->initFromGdResource($this->data);

        case $this->isImagick():
            return $this->initFromImagick($this->data);

        case $this->isInterventionImage():
            return $this->initFromInterventionImage($this->data);

        case $this->isSplFileInfo():
            return $this->initFromPath($this->data->getRealPath());

        case $this->isBinary():
            return $this->initFromBinary($this->data);

        case $this->isUrl():
            return $this->initFromUrl($this->data);

        case $this->isStream():
            return $this->initFromStream($this->data);

        case $this->isDataUrl():
            return $this->initFromBinary($this->decodeDataUrl($this->data));

        case $this->isFilePath():
            return $this->initFromPath($this->data);

        // isBase64 has to be after isFilePath to prevent false positives
        case $this->isBase64():
            return $this->initFromBinary(base64_decode($this->data));

        default:
            throw new Exception\NotReadableException("Image source not readable");
    }
}

У меня установлен gd libery.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...