Errors on upload/resize?

See all posts Reply

Errors on upload/resize? new!
by Murray Summers, 12 years, 11 months ago
Can anyone see why this code would be giving me the errors shown (I have included light debugging code)? Yet, when I run the distributed upload-index.php file, it works fine!

The image appears to upload fine, since I can see the temp file in the destination folder. But that's all I get....

// ---------- IMAGE UPLOAD ----------

// we create an instance of the class, giving as argument the PHP object
// corresponding to the file field from the form
// All the uploads are accessible from the PHP object $_FILES
$handle = new Upload($_FILES['image1']);

// then we check if the file has been uploaded properly
// in its *temporary* location in the server (often, it is /tmp)
if ($handle->uploaded) {
echo "uploaded";
echo $handle->file_src_name;

// yes, the file is on the server
// below are some example settings which can be used if the uploaded file is an image.
$handle->image_resize            = true;
$handle->image_ratio_y           = true;
$handle->image_x                 = 169;
$handle->image_border              = '1px';
$handle->image_border_color      = '#FFFFFF';
$handle->image_watermark          = '_img/logotree-watermark3.png';
$handle->file_overwrite          = true;

// now, we start the upload 'process'. That is, to copy the uploaded file
// from its temporary location to the wanted location
// It could be something like $handle->Process('/home/www/my_uploads/');

$handle->Process($dir_dest);

echo "
" . $handle->file_dst_path . "";
echo $handle->file_dst_name . "";

// we check if everything went OK
if ($handle->processed) {
  // everything was fine !
  echo 'file uploaded with success';
  echo $handle->file_dst_name;
  $info = getimagesize($handle->file_dst_pathname);
  echo '' . $info['mime'] . '  -  ' . $info[0] . ' x ' . $info[1] .'  -  '
    . round(filesize($handle->file_dst_pathname)/256)/4 . 'KB';
  echo '  link to the file just uploaded: ' . $dir_pics.'/' . $handle->file_dst_name;
} else {
  // one error occured
  echo 'file not uploaded to the wanted location';
  echo '  Error: ' . $handle->error . '';
}

// we now process the image a second time, with some other settings
$handle->image_resize            = true;
$handle->image_ratio_y           = true;
$handle->image_x                 = 84;
$handle->image_border              = '1px';
$handle->image_border_color      = '#FF0000';
$handle->file_new_name_body      = 'foo2'; 
$handle->file_overwrite          = true;

$handle->Process($dir_dest);

ERRORS

file not uploaded to the wanted location Error: Error copying file on the server. copy() failed.
file not uploaded to the wanted location Error: No correct temp source file. Can't carry on a process.


PHP Warning: copy(test2\32f7981c7c7564468c0a3048b6f27d55.jpg) [function.copy]: failed to open stream: No such file or directory in W:\Webspace\murray99\gwssite\savannahweddings.com\www\_class\class.upload.php on line 4960 PHP Warning: unlink(test2\32f7981c7c7564468c0a3048b6f27d55.jpg) [function.unlink]: No such file or directory in W:\Webspace\murray99\gwssite\savannahweddings.com\www\_class\class.upload.php on line 5004Reply
Re: Errors on upload/resize? new!
by colin, 12 years, 11 months ago
Can you copy here the log produced by the class? It looks like you have an open_basedir restriction in place, but the class should be able to deal with that.Reply
Re: Errors on upload/resize? new!
by Murray Summers, 12 years, 11 months ago
The log output is shown in the above post (without the fieldset, etc.), beginning with 'file not uploaded...'

I'm sure there is not an open_basedir restriction in place, because uploading with your demo page (upload.php + index-upload.php) to the same location works!Reply
Re: Errors on upload/resize? new!
by colin, 12 years, 11 months ago
The log is output with the following line:
echo $handle->log;
Reply
Re: Errors on upload/resize? new!
by Murray Summers, 12 years, 11 months ago
Oh - heh, oops.

system information
- class version : 0.31
- operating system : WINNT
- PHP version : 4.4.7
- GD version : 2.0.28
- supported image types : png jpg gif bmp
- open_basedir : no restriction
- upload_max_filesize : 2M (2097152 bytes)
- language : en_GB
source is an uploaded file
- upload OK
- file name OK
determining MIME type
- Checking MIME type with Fileinfo PECL extension
Fileinfo PECL extension not available
- Checking MIME type with UNIX file() command
UNIX file() command not availabled
- Checking MIME type with mime.magic file (mime_content_type())
mime_content_type() is not available
- Checking MIME type with getimagesize()
MIME type detected as image/jpeg by PHP getimagesize() function
- MIME validated as image/jpeg
source variables
- You can use all these before calling process()
file_src_name : beach.jpg
file_src_name_body : beach
file_src_name_ext : jpg
file_src_pathname : C:\WINNT\TEMP\php809.tmp
file_src_mime : image/jpeg
file_src_size : 1800554 (max= 2097152)
file_src_error : 0
- source file is an image
image_src_x : 2592
image_src_y : 3872
image_src_pixels : 10036224
image_src_type : jpg
image_src_bits : 8
process file to test2\
- file size OK
- file mime OK : image/jpeg
- file name safe format
- destination variables
file_dst_path : test2\
file_dst_name_body : beach
file_dst_name_ext : jpg
- no auto_rename if same filename exists
- destination file details
file_dst_name : beach.jpg
file_dst_pathname : test2\beach.jpg
- no overwrite checking
- attempting to use a temp file: file created
temp file is: test2\8ff7a42bcd5b5433c46ac8870f1614b2.jpg
- the file is not an image!
- no image processing wanted
- error: Error copying file on the server. copy() failed.Reply
Re: Errors on upload/resize? new!
by colin, 12 years, 11 months ago
I am not sure what is going on. I don't have a Windows box to test it.

Tru to remove the @ on line 3653, to see whether it acn read the newly created temp file:
getimagesize($this->file_src_pathname)

Note that your setup is very insecure, since your system doesn't provide any reliable way to check the MIME type. This is a serious security hole, and can permit an attacker to hack into your system.Reply
Re: Errors on upload/resize? new!
by Murray Summers, 12 years, 11 months ago
It was a stupid pathing error to the destination folder. I now have this working the way I want. And the security issue was caused by the fact that the path to the destination folder was wrong, so the getimagesize() command couldn't find the image to do its work!

Sorry for the bandwidth....Reply
Re: Errors on upload/resize? new!
by Jefferson, 10 years, 6 months ago
How have you changed the path? I've tryed both relative and absolute path, but none worked.Reply