Problem in uploading script
Posted by: webface (---.cpe.net.cable.rogers.com)
Date: March 13, 2008 01:36AM

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"winking smiley;
$res = ImageGIF($im);
}
break;
case 2:
if ($this->save_to_file) {
$res = ImageJPEG($im,$filename,$this->quality);
}
else {
header("Content-type: image/jpeg"winking smiley;
$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"winking smiley;
$res = ImagePNG($im, NULL, $quality);
}
}
else {
if ($this->save_to_file) {
$res = ImagePNG($im, $filename);
}
else {
header("Content-type: image/png"winking smiley;
$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-"winking smiley;
$temp = @fopen($tmpfname, "w"winking smiley;
if ($temp) {
@fwrite($temp, @file_get_contents($from_name)) or die("Cannot download image"winking smiley;
@fclose($temp);
$from_name = $tmpfname;
}
else {
die("Cannot create temp file"winking smiley;
}
}

// check if file exists
if (!file_exists($from_name)) die("Source image does not exist!"winking smiley;

// 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"winking smiley;

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"winking smiley;
readfile($from_name);
break;
case 2:
header("Content-type: image/jpeg"winking smiley;
readfile($from_name);
break;
case 3:
header("Content-type: image/png"winking smiley;
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

Options: ReplyQuote
Re: Problem in uploading script
Posted by: yfastud (Moderator)
Date: March 13, 2008 02:06AM

From first file, do you only post part of code or is it really missing the closing tag? Also, how about file thumbConfig.php, you're sure it's all ok?

Have fun,

FREE One A Day
FREE Photo
FREE Games
FREE Websites
FREE Portable GPS
FREE WAMP Guides

Options: ReplyQuote
Re: Problem in uploading script
Posted by: webface (---.cpe.net.cable.rogers.com)
Date: March 13, 2008 02:37AM

..?> oops

//thumbConfig

<?php
$ENABLE_THUMB = 1; //1 for Yes, 0 for false
$ENABLE_RESIZE = 1; //1 for Yes, 0 for false
$MAX_RESIZE_WIDTH = 400;
$MAX_RESIZE_HEIGHT = 400;
$MAX_THUMB_WIDTH = 100;
$MAX_THUMB_HEIGHT = 100;
?>


i've double checked what i could, not quite sure if file permissions can be set here like on server but thats the same folder and file structure used online for it.

Options: ReplyQuote
Re: Problem in uploading script
Posted by: yfastud (Moderator)
Date: March 13, 2008 03:46AM

what did you use to handle image? GD or Imagemagik? If gd, did you enable it through wamp tray icon? If imagemagick, did you install and set it up before running your script?

Have fun,

FREE One A Day
FREE Photo
FREE Games
FREE Websites
FREE Portable GPS
FREE WAMP Guides

Options: ReplyQuote
Re: Problem in uploading script
Posted by: southbeach (---.not.configured)
Date: March 13, 2008 03:17PM

I would be more interested in looking at your <form ....> tag in the calling HTML page. Unless you use proper object properties, it will never work ...

If your <form ...> tag method is NOT 'post', it will not work ...
If your <form ...> tag is missing ENCTYPE='multipart/form-data', it will not work ...

Funny thing is that the errors are similar to those you are getting ... eye rolling smiley


Regards,

Options: ReplyQuote
Re: Problem in uploading script
Posted by: webface (---.region1.highspeedunplugged.bell.ca)
Date: March 13, 2008 03:34PM

The front end to the app is in flash and uses file reference to call the upload script:


var uploadScriptconfused smileytring = 'thumbUpload.php?folder='+folder;
var uploaded:Boolean = fileRef.upload(uploadScript);


This calls the upload script and is the same settings used on the other uploads which work fine. I have gd support on in WAMP. I just downloaded and installed imagemagick on my pc but I dont know how to configure it in WAMP. Some tutorial

[www.vbulletin.com] explains an install but the steps i could not follow:

"In the WAMP menu choose: PHP Settings/PHP Extentions/Add Extention"

My WAMP menu deos not have Add extensions anywhere. Maybe this is not for WAMP5. So i'm still stuck. How do I add imagemagick to my WAMP to test. Any and all help is welcome.

Cheers,
webfaCe

Options: ReplyQuote
Re: Problem in uploading script
Posted by: yfastud (Moderator)
Date: March 13, 2008 03:42PM

He already posted that the script run perfectly on his hosting service, so I don't think there is a problem w/i his script except if it was implemented w/ absolute paths

Moreover, most web hosts are already setup either gd or Imagemagik so users can work w/ images. On the other words, they will likely announce what and only those specific stuffs that the users can do on their host. On the other hands, you can do almost everything w/ wamp; however, you're either enable it or set it up yourself to meed your needs

Have fun,

FREE One A Day
FREE Photo
FREE Games
FREE Websites
FREE Portable GPS
FREE WAMP Guides

Options: ReplyQuote
Re: Problem in uploading script
Posted by: webface (---.region1.highspeedunplugged.bell.ca)
Date: March 13, 2008 04:06PM

I now have imagemagick and gd installed. I rebooted and ran the script. Still the same errors. This is my wamp setup at work. Same issue as the one at home. Error log:

[13-Mar-2008 10:59:33] PHP Warning: move_uploaded_file(temporary/credit_cards.jpg) [<a href='function.move-uploaded-file'>function.move-uploaded-file</a>]: failed to open stream: No such file or directory in C:\wamp\www\cms\thumbUpload.php on line 10

[13-Mar-2008 10:59:33] PHP Warning: move_uploaded_file() [<a href='function.move-uploaded-file'>function.move-uploaded-file</a>]: Unable to move 'C:\wamp\tmp\php7CF3.tmp' to 'temporary/credit_cards.jpg' in C:\wamp\www\cms\thumbUpload.php on line 10

[13-Mar-2008 10:59:33] PHP Warning: getimagesize(temporary/credit_cards.jpg) [<a href='function.getimagesize'>function.getimagesize</a>]: failed to open stream: No such file or directory in C:\wamp\www\cms\thumbUpload.php on line 14

I tried switching _GET and _POST in the upload script with no luck.

*He who has the knowledge, let him share.

webfaCe

Options: ReplyQuote
Re: Problem in uploading script
Posted by: yfastud (Moderator)
Date: March 13, 2008 05:16PM

What script are you using? Is it a well-known script or your own-made? Did you check to see if you have this folder "temporary" in your script's location? Remember, wamp use different name for folder that handle temp files, so either you have create 1 or edit the config file; however, be careful when edit config file since everything, I mean w/ different scripts, after that has to base on that edit

Have fun,

FREE One A Day
FREE Photo
FREE Games
FREE Websites
FREE Portable GPS
FREE WAMP Guides

Options: ReplyQuote
Re: Problem in uploading script
Posted by: southbeach (---.not.configured)
Date: March 13, 2008 05:43PM

Simplify the explanation and please provide steps followed prior to the error. I still want to see you <form ...> tag.

Options: ReplyQuote
Re: Problem in uploading script
Posted by: webface (---.region1.highspeedunplugged.bell.ca)
Date: March 13, 2008 06:28PM

Southbeach, thanks for your input but there are no forms used here. The cms is flash based and uses actionscript. The upload call uses fileReference which was down loaded from the adobe site and has worked for me since 2004 in all my apps. I DONT THINK IT IS ANYTHING TO DO WITH THE CODE. It works online in over 10 cms' I've installed

The front end to the app is in flash and uses file reference to call the upload script:

//.as

var uploadScriptconfused smileytring = 'thumbUpload.php?folder='+folder;
var uploaded:Boolean = fileRef.upload(uploadScript);

//----------------

This calls the upload script and is the same settings used on the other uploads which work fine.

There is no form tag, the front end uses flash. Like i said, there are 3 upload scripts in the app all of which work online. The difference between this script here and the 2 others is

1. this upload uses _GET to acquire the $folder value. I have switched around _GET and _POST no diff. so i left it on _GET like on the server.


This upload works well online with no hiccups. I'd rather not mess around with the config file till i'm sure thats where the problem lies. If there are steps to follow to check into this, I'm all ears.

*He who has more insight,...let him share. !!

both GD and imagemagick are running fine

cheers,
Tommy

Options: ReplyQuote
Re: Problem in uploading script
Posted by: southbeach (---.not.configured)
Date: March 13, 2008 07:18PM

The use of _GET and _POST is based on how the data is submitted to processing script. When in doubt, use _REQUEST ... you might want to give it a try.

I don't know what to tell you, other than suggesting you read through [us2.php.net] and hope you find an answer there.

Options: ReplyQuote
Re: Problem in uploading script
Posted by: webface (---.region1.highspeedunplugged.bell.ca)
Date: March 14, 2008 04:17PM

I tried moving the temp directory to a location under www. The other 2 uploads still work fine but this here gives me the same error. I have looked in the php manual on this and there is nothing there that sheds further light on this. I'm pretty dissapointed at this point. I got everything else configured and working but that. How can i learn this language if I cant get it to work like my server deos?


[14-Mar-2008 11:08:18] PHP Warning: move_uploaded_file(temporary/flower.jpg) [<a href='function.move-uploaded-file'>function.move-uploaded-file</a>]: failed to open stream: No such file or directory in C:\wamp\www\cms\thumbUpload.php on line 10

[14-Mar-2008 11:08:18] PHP Warning: move_uploaded_file() [<a href='function.move-uploaded-file'>function.move-uploaded-file</a>]: Unable to move 'C:\wamp\www\temp\php9B91.tmp' to 'temporary/flower.jpg' in C:\wamp\www\cms\thumbUpload.php on line 10

[14-Mar-2008 11:08:18] PHP Warning: getimagesize(temporary/flower.jpg) [<a href='function.getimagesize'>function.getimagesize</a>]: failed to open stream: No such file or directory in C:\wamp\www\cms\thumbUpload.php on line 14

If anyone else is still reading this and can help. Please do.

cheers,
webfaCe

Options: ReplyQuote
Re: Problem in uploading script [RESOLVED]
Posted by: webface (---.cpe.net.cable.rogers.com)
Date: March 18, 2008 12:11AM

i had to set file permissions to my www directory using >Properties>Security tab and enabling folder permissions for my USER. WAMP rocks again then.. as long as I can configure PEAR.


cheers
webfaCe

Options: ReplyQuote


Sorry, only registered users may post in this forum.