class.upload.php is a powerful and mature PHP class to manage uploaded files, and manipulate images in many ways. The script is available under a GPL license.
I'm having a problem getting the script to prepend "thumb_" to the filename. here's my snippet:
// ---------- 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['my_field']);
// then we check if the file has been uploaded properly
// in its *temporary* location in the server (often, it is /tmp)
if ($handle->uploaded) {
// 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_ratio_x = true;
$handle->image_convert = 'jpg';
$handle->image_x = 500;
$handle->image_y = 500;
// 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('./uploaded_images/');
// we check if everything went OK
if ($handle->processed) {
// everything was fine !
echo($handle->file_dst_name . " uploaded successfully");
/*Saving the filename to the database. This code hopefully gets changed to something prettier down the road.*/
if(!ISSET($adcreate_image_1) OR ($adcreate_image_1=='')){
mysql_query("UPDATE classifieds_ads_temp SET image_1 = '$handle->file_dst_name' WHERE user_id = $user_id") or die("Failed to update ads_temp database.
" . mysql_error());
}else{
if(!ISSET($adcreate_image_2) OR ($adcreate_image_2=='')){
mysql_query("UPDATE classifieds_ads_temp SET image_2 = '$handle->file_dst_name' WHERE user_id = $user_id") or die("Failed to update ads_temp database.
" . mysql_error());
}else{
if(!ISSET($adcreate_image_3) OR ($adcreate_image_3=='')){
mysql_query("UPDATE classifieds_ads_temp SET image_3 = '$handle->file_dst_name' WHERE user_id = $user_id") or die("Failed to update ads_temp database.
" . mysql_error());
}else{
if(!ISSET($adcreate_image_4) OR ($adcreate_image_4=='')){
mysql_query("UPDATE classifieds_ads_temp SET image_4 = '$handle->file_dst_name' WHERE user_id = $user_id") or die("Failed to update ads_temp database.
" . mysql_error());
}else{
if(!ISSET($adcreate_image_5) OR ($adcreate_image_5=='')){
mysql_query("UPDATE classifieds_ads_temp SET image_5 = '$handle->file_dst_name' WHERE user_id = $user_id") or die("Failed to update ads_temp database.
" . mysql_error());
}else{
if(!ISSET($adcreate_image_6) OR ($adcreate_image_6=='')){
mysql_query("UPDATE classifieds_ads_temp SET image_6 = '$handle->file_dst_name' WHERE user_id = $user_id") or die("Failed to update ads_temp database.
" . mysql_error());
}else{
}
}
}
}
}
}
}else{
// one error occured
echo("file failed to upload to the specified destination
Error: " . $handle->error . "");
}
// we now process the image a second time, with some other settings
$handle->file_name_body_pre = 'thumb_';
$handle->image_resize = true;
$handle->image_ratio_y = true;
$handle->image_convert = 'jpg';
$handle->image_x = 100;
$handle->Process('./uploaded_images/');
// we check if everything went OK
if ($handle->processed) {
// everything was fine !
echo($handle->file_dst_name . "created successfully");
}else{
// one error occured
echo("Thumbnail generation failed. Error: " . $handle->error . "");
}
// we delete the temporary files
$handle-> Clean();
}else{
// if we're here, the upload file failed for some reasons
// i.e. the server didn't receive the file
echo("file failed to upload to the specified destination Error: " . $handle->error . "");
}
Instead of thumb_imagename, I'm getting imagename_1 for the thumbnail I'm trying to create.
Any help on how to get this working would be greatly appreciated.
Thank you very much for your response and I apologize for the ignorant question, but am I looking for an error log specific to the upload class? If so, where would I find it?
The php error log is showing nothing concerning this.
I'm having a problem getting the script to prepend "thumb_" to the filename. here's my snippet:
Instead of thumb_imagename, I'm getting imagename_1 for the thumbnail I'm trying to create.
Any help on how to get this working would be greatly appreciated.
thanks,
json
The php error log is showing nothing concerning this.
thanks,
json