drnx3715 2016-05-06 14:06
浏览 23

WideImage仅适用于某些图像

WideImage is only working for some images. I can't figure out why, because the images are same filetype and same dimensions.

Here is my code

<?php
error_reporting(E_ALL);

include 'WideImage/WideImage.php';

function make_thumb($src, $dest, $desired_width) {
    try {
        WideImage::loadFromFile($src)->resize($desired_width, 50)->saveToFile($dest);
    }
    catch (Exception $e) {
        echo 'EXCEPTION: '.$e;
    }   
}
?>

Function call

echo 'Thumb Creation Started';
make_thumb($filename, $thumbname, 100);
echo 'Thumb Creation Finished';

I'm receiving the following errror:

EDIT: This error is only occuring when i resend the data with firebug. At first there is no error shown.

Thumb Creation StartedEXCEPTION: exception 'WideImage_InvalidImageSourceException' with message 'File '/kunden/homepages/33/d582216481/htdocs/uploads/downloads/image .png' appears to be an invalid image source.' in /homepages/33/d582216481/htdocs/includes /WideImage/WideImage.php:226 Stack trace:

0 /homepages/33/d582216481/htdocs/includes/phpThumb.php(12):

WideImage::loadFromFile(' /kunden/homepag...')

1 /homepages/33/d582216481/htdocs/includes/addDownload.php(60):

make_thumb('/kunden/homepag ...', '/kunden/homepag...', 100)

2 {main}Thumb Creation Started

Can somebody explain, why it is working for some images, and for some not??

<?php

error_reporting(E_ALL);

// Basic Conf
require_once ('basic_config.php');
// PHP Thumb
require_once ('phpThumb.php');
// DB INIT
require_once ($full_url.'includes/db.php');

// GET DATA FROM POST
$pid = $_POST['downloadProdukt'];
$downloadBezeichnung = $_POST['downloadBezeichnung'];
$downloadDatei = str_replace(' ', '_', $_FILES['downloadDatei']['name']);
$downloadKategorie = $_POST['downloadKategorie'];
$downloadSize = $_FILES['downloadDatei']['size'];

// GET Image adjustments
$image_info = getimagesize($_FILES["downloadDatei"]["tmp_name"]);
$image_width = $image_info[0];
$image_height = $image_info[1];

// GET FOLDER OF THE PRODUCT
$cols = Array ("PID","OrdnerName");
$db->where ('PID', $pid);
$produkte = $db->get ("produkt", null, $cols);
if ($db->count > 0){
    foreach ($produkte as $produkt) {
        $uploadFolder = $produkt['OrdnerName'];
    }
}

// FILE
$filePath = $upload_url . $uploadFolder . "downloads/";
$rel_file_path = $uploadFolder . "downloads/";
$filename = $filePath .  $downloadDatei;
$thumbname = $filePath .  "thumb_" . $downloadDatei;

// Falls Ordner nicht existiert erstelle neu
if (!file_exists($filePath)) {
    mkdir($filePath, 0777, true);
}

// Move file to Dir
if (move_uploaded_file($_FILES['downloadDatei']['tmp_name'], $filename)) {
    //echo "Original Datei erfolgreich hochgeladen.
";
} else {
    echo "Möglicherweise eine Dateiupload-Attacke!
";
}

// IF Image --> Generate Thumb
if (
        // Wenn dateityp BILD
        $_FILES['downloadDatei']['type'] == 'image/jpeg' OR
        $_FILES['downloadDatei']['type'] == 'image/png' OR
        $_FILES['downloadDatei']['type'] == 'image/gif'
){
    echo 'Thumb Creation Started';
    make_thumb($filename, $thumbname, 100);
    $thumbname = "thumb_" . $downloadDatei;
    echo 'Thumb Creation Finished';
} else {
    $thumbname = null;
    echo 'Kein Thumb';
}

// EXECUTE QUERY
$data = Array ("PID" => $pid,
                'DownloadBez' => $downloadBezeichnung,
                'DownloadKat' => $downloadKategorie,
                'DownloadDatei' => $downloadDatei,
                'DownloadOrdner' => $rel_file_path,
                'DownloadSize' => $downloadSize,
                'DownloadThumb' => $thumbname
            );
$id = $db->insert ('downloads', $data);

?>

Not working working

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 求数据集和代码#有偿答复
    • ¥15 关于下拉菜单选项关联的问题
    • ¥20 java-OJ-健康体检
    • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
    • ¥15 使用phpstudy在云服务器上搭建个人网站
    • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
    • ¥15 vue3+express部署到nginx
    • ¥20 搭建pt1000三线制高精度测温电路
    • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
    • ¥15 画两个图 python或R