Reputation: 41
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.\n";
} else {
echo "Möglicherweise eine Dateiupload-Attacke!\n";
}
// 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);
?>
Upvotes: 1
Views: 1678