Witajcie,
Próbuję napisać prymitywny skrypcik, który po wgraniu pliku graficznego na serwer zmieni jego rozmiar i zapisze miniaturę w katalogu podrzędnym o nazwie thumb.
Problem jest tego typu, że skrypt (resize.php) jest zapisany w innym katalogu (admin) a wgrane pliki graficzne w innym (files/products), kiedy plik resize.php i plik graficzny (np. example.jpg) są w tym samym katalogu nie ma problemu, natomiast kiedy podaję ścieżkę relatywną (../file/products/example.jpg) do pliku graficznego dostaję komunikat:
Error Invalid Image TypeCzy jest jakaś rada jak to "ugryść" Czy plik resize.php musi być w katalogu z obrazkami?
Kod resize.php -
http://scripts.ringsworld.com/image-handli...resize.php.html<?php
/*
Version 1.0 Created by: Ryan Stemkoski
Questions or comments: ryan <at> ipowerplant <dot> com
Purpose: This script can be used to resize one or more images. It will save the file to a directory and output the path to that directory which you
can display or write to a databse.
TO USE, SET:
$filename = image to be resized
$newfilename = added to filename to for each use to keep from overwriting images created example thumbnail_$filename is how it will be saved.
$path = where the image should be stored and accessed.
$newwidth = resized width could be larger or smaller
$newheight = resized height could be larger or smaller
SAMPLE OF FUNCTION: makeimage('image.jpg', 'fullimage_', 'imgs/', 250, 250)
Include the file containing the function in your document and simply call the function with the correct parameters and your image will be resized.
*/
//IMAGE RESIZE FUNCTION FOLLOW ABOVE DIRECTIONS
function makeimage($filename, $newfilename, $path, $newwidth, $newheight) {
//SEARCHES IMAGE NAME STRING TO SELECT EXTENSION (EVERYTHING AFTER . )
$image_type = strstr($filename, '.');
//SWITCHES THE IMAGE CREATE FUNCTION BASED ON FILE EXTENSION
switch($image_type) {
case '.jpg':
$source = imagecreatefromjpeg($filename);
break;
case '.png':
$source = imagecreatefrompng($filename);
break;
case '.gif':
$source = imagecreatefromgif($filename);
break;
default:
echo("Error Invalid Image Type"); break;
}
//CREATES THE NAME OF THE SAVED FILE
$file = $newfilename . $filename;
//CREATES THE PATH TO THE SAVED FILE
$fullpath = $path . $file;
//FINDS SIZE OF THE OLD FILE
//CREATES IMAGE WITH NEW SIZES
$thumb = imagecreatetruecolor($newwidth, $newheight);
//RESIZES OLD IMAGE TO NEW SIZES
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
//SAVES IMAGE AND SETS QUALITY || NUMERICAL VALUE = QUALITY ON SCALE OF 1-100
imagejpeg($thumb, $fullpath, 60);
//CREATING FILENAME TO WRITE TO DATABSE
$filepath = $fullpath;
//RETURNS FULL FILEPATH OF IMAGE ENDS FUNCTION
return $filepath;
}
?>
Kod sprawdzający test.php
<?php
include ('resize.php');
$image = 'example.jpg';
$rootpath = '../files/products/';
echo $rootpath.$image."<br><br><br>";
echo "Plik " .$image. " istnieje<br><br>"; echo "Próbuję utworzyć miniaturę ".$image."<br><br>";
makeimage($rootpath.$image, '', '../files/products/thumb/', 67, 67);
} else {
echo "The file " .$image. " does not exist"; }
?>