My WAMP is setup and configured. I am running into an issue with an application that has already been tested online. Its a php based cms for multimedia. It has 3 different upload scripts which upload different types of filetypes. The one that deals with images has a thumbnail class that auto creates thumbnails of each upload. This app has been tested and is used online for a few sites already but i cannot get the image upload with thumbnail script to work in WAMP. I looked in the error logs and even though theres more info, my knowledge of php or wamp is rather limited. I was not responsible for the php script part of the project but I am using it as a template to learn php e.t.c.. Here is the error log
[12-Mar-2008 18:18:32] PHP Warning: move_uploaded_file(temporary/Water lilies.jpg) [<a href='function.move-uploaded-file'>function.move-uploaded-file</a>]: failed to open stream: No such file or directory in E:\wamp\www\Apps\cms\thumbUpload.php on line 10
[12-Mar-2008 18:18:32] PHP Warning: move_uploaded_file() [<a href='function.move-uploaded-file'>function.move-uploaded-file</a>]: Unable to move 'E:\wamp\tmp\php1A.tmp' to 'temporary/Water lilies.jpg' in E:\wamp\www\Apps\cms\thumbUpload.php on line 10
[12-Mar-2008 18:18:32] PHP Warning: getimagesize(temporary/Water lilies.jpg) [<a href='function.getimagesize'>function.getimagesize</a>]: failed to open stream: No such file or directory in E:\wamp\www\Apps\cms\thumbUpload.php on line 14
The php works online. I'm inclined to think its something with my settings. Here is the php..
<?php
require_once "thumbConfig.php";
include_once "image.class.php";
$folder = $_GET['folder'];
$tmp_path = "temporary/".$_FILES['Filedata']['name']; //path for temporary folder
$actual_path = $folder."/".$_FILES['Filedata']['name']; //actual image path
$thumb_file_name = substr($_FILES['Filedata']['name'],0,strrpos($_FILES['Filedata']['name'],'.'))."_thumb".substr($_FILES['Filedata']['name'],strrpos($_FILES['Filedata']['name'],'.'));
$thumb_path = $folder."/thumbs/".$thumb_file_name; //thumbnail path
move_uploaded_file($_FILES['Filedata']['tmp_name'], $tmp_path); //upload the file
//exif_imagetype may not work every where
//$type = exif_imagetype($tmp_path);
list($width, $height, $type, $attr) = getimagesize($tmp_path); //get image details
if ($type == 1 || $type == 2 || $type == 3) { //if JPG/GIF/PNG
//check for resize
if($ENABLE_RESIZE==1 && ($width > $MAX_RESIZE_WIDTH || $height > $MAX_RESIZE_HEIGHT)) {
//then resize
$img = new Zubrag_image;
// initialize
$img->max_x = $MAX_RESIZE_WIDTH;
$img->max_y = $MAX_RESIZE_HEIGHT;
$img->image_type = $type;
// generate thumbnail
$img->GenerateThumbFile($tmp_path, $actual_path);
}
else {
rename($tmp_path, $actual_path); //move to actual folder
}
if($ENABLE_THUMB==1) {
//thumbnail processing
$img = new Zubrag_image;
// initialize
$img->max_x = $MAX_THUMB_WIDTH;
$img->max_y = $MAX_THUMB_HEIGHT;
$img->image_type = $type;
// generate thumbnail
$img->GenerateThumbFile($actual_path, $thumb_path);
}
}
else {
unlink($tmp_path); //remove any junk uploaded
}
and the thumbnail class
____________________________________________
<?php
###############################################################
# Thumbnail Image Class
###############################################################
# src [
www.zubrag.com]
###############################################################
class Zubrag_image {
var $save_to_file = true;
var $image_type = -1;
var $quality = 100;
var $max_x = 100;
var $max_y = 100;
var $cut_x = 0;
var $cut_y = 0;
function SaveImage($im, $filename) {
$res = null;
// ImageGIF is not included into some GD2 releases, so it might not work
// output png if gifs are not supported
if(($this->image_type == 1) && !function_exists('imagegif')) $this->image_type = 3;
switch ($this->image_type) {
case 1:
if ($this->save_to_file) {
$res = ImageGIF($im,$filename);
}
else {
header("Content-type: image/gif"
;
$res = ImageGIF($im);
}
break;
case 2:
if ($this->save_to_file) {
$res = ImageJPEG($im,$filename,$this->quality);
}
else {
header("Content-type: image/jpeg"
;
$res = ImageJPEG($im, NULL, $this->quality);
}
break;
case 3:
if (PHP_VERSION >= '5.1.2') {
// Convert to PNG quality.
// PNG quality: 0 (best quality, bigger file) to 9 (worst quality, smaller file)
$quality = 9 - min( round($this->quality / 10), 9 );
if ($this->save_to_file) {
$res = ImagePNG($im, $filename, $quality);
}
else {
header("Content-type: image/png"
;
$res = ImagePNG($im, NULL, $quality);
}
}
else {
if ($this->save_to_file) {
$res = ImagePNG($im, $filename);
}
else {
header("Content-type: image/png"
;
$res = ImagePNG($im);
}
}
break;
}
return $res;
}
function ImageCreateFromType($type,$filename) {
$im = null;
switch ($type) {
case 1:
$im = ImageCreateFromGif($filename);
break;
case 2:
$im = ImageCreateFromJpeg($filename);
break;
case 3:
$im = ImageCreateFromPNG($filename);
break;
}
return $im;
}
// generate thumb from image and save it
function GenerateThumbFile($from_name, $to_name) {
// if src is URL then download file first
$temp = false;
if (substr($from_name,0,7) == 'http://') {
$tmpfname = tempnam("tmp/", "TmP-"
;
$temp = @fopen($tmpfname, "w"
;
if ($temp) {
@fwrite($temp, @file_get_contents($from_name)) or die("Cannot download image"
;
@fclose($temp);
$from_name = $tmpfname;
}
else {
die("Cannot create temp file"
;
}
}
// check if file exists
if (!file_exists($from_name)) die("Source image does not exist!"
;
// get source image size (width/height/type)
// orig_img_type 1 = GIF, 2 = JPG, 3 = PNG
list($orig_x, $orig_y, $orig_img_type, $img_sizes) = @GetImageSize($from_name);
// cut image if specified by user
if ($this->cut_x > 0) $orig_x = min($this->cut_x, $orig_x);
if ($this->cut_y > 0) $orig_y = min($this->cut_y, $orig_y);
// should we override thumb image type?
$this->image_type = ($this->image_type != -1 ? $this->image_type : $orig_img_type);
// check for allowed image types
if ($orig_img_type < 1 or $orig_img_type > 3) die("Image type not supported"
;
if ($orig_x > $this->max_x or $orig_y > $this->max_y) {
// resize
$per_x = $orig_x / $this->max_x;
$per_y = $orig_y / $this->max_y;
if ($per_y > $per_x) {
$this->max_x = $orig_x / $per_y;
}
else {
$this->max_y = $orig_y / $per_x;
}
}
else {
// keep original sizes, i.e. just copy
if ($this->save_to_file) {
@copy($from_name, $to_name);
}
else {
switch ($this->image_type) {
case 1:
header("Content-type: image/gif"
;
readfile($from_name);
break;
case 2:
header("Content-type: image/jpeg"
;
readfile($from_name);
break;
case 3:
header("Content-type: image/png"
;
readfile($from_name);
break;
}
}
return;
}
if ($this->image_type == 1) {
// should use this function for gifs (gifs are palette images)
$ni = imagecreate($this->max_x, $this->max_y);
}
else {
// Create a new true color image
$ni = ImageCreateTrueColor($this->max_x,$this->max_y);
}
// Fill image with white background (255,255,255)
$white = imagecolorallocate($ni, 255, 255, 255);
imagefilledrectangle( $ni, 0, 0, $this->max_x, $this->max_y, $white);
// Create a new image from source file
$im = $this->ImageCreateFromType($orig_img_type,$from_name);
// Copy the palette from one image to another
imagepalettecopy($ni,$im);
// Copy and resize part of an image with resampling
imagecopyresampled(
$ni, $im, // destination, source
0, 0, 0, 0, // dstX, dstY, srcX, srcY
$this->max_x, $this->max_y, // dstW, dstH
$orig_x, $orig_y); // srcW, srcH
// save thumb file
$this->SaveImage($ni, $to_name);
if($temp) {
unlink($tmpfname); // this removes the file
}
}
}
?>
//________________________________
This app works fully online. I'm trying to get it to work fully on WAMP so I can learn from it but not all its functions as described above are working. This upload script and thumbnail class here do not work on WAMP and those are the error logs traced out when trying to use it. Any kind of insight will be appreciated in my effort to replicate my online server environment on WAMP. The logs looks to me like it attemped to upload a file but didnt move the temp file uploaded from the tmp directory into the destination folder... but really, what do i know. HELP!
cheers,
webfaCe