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 using the following code to copy the images to the necessary directories and to edit the xml file I want to edit with the uploaded filenames. If someone could give me some insight on how to use one of the post-processing variables to pass their values to the xml file wold be greatly appreciated.
include('class.upload.php');
$filehandler = new upload($_FILES['image_field']);
if ($filehandler->uploaded) {
// save uploaded image with no changes
$filehandler->file_overwrite = true;
$filehandler->Process('load/images/');
if ($filehandler->processed) {
echo 'original image copied';
} else {
echo 'error : ' . $filehandler->error;
}
// save uploaded image with a new name,
// resized to 160px height
// $filehandler->file_new_name_body = 'image_resized';
//$filehandler->image_convert = jpg;
$filehandler->image_resize = true;
$filehandler->file_overwrite = true;
$filehandler->image_y = 160;
$filehandler->image_ratio_x = true;
$filehandler->Process('load/thumbs/');
if ($filehandler->processed) {
echo 'image renamed, resized y=160
and converted to JPG';
$filehandler->Clean();
} else {
echo 'error : ' . $filehandler->error;
}
}
$thumbimage = array(
'thumbnail' => 'Thumbnail file name from class.upload.php',);
$fullimage = array(
'imageload' => 'Full image file name from class.upload.php',);
$imagetext = array(
//Can still use description parameter from form in index php file
'description' => $_POST['description_text'],);
$doc = new DOMDocument();
$doc->load( 'load/config.xml' );
$doc->formatOutput = true;
$r = $doc->getElementsByTagName("settings")->item(0);
$b = $doc->createElement("image");
$thumb_path = $doc->createElement("thumb_path");
$thumb_path->appendChild(
$doc->createTextNode( $thumbimage["thumbnail"] )
);
$b->appendChild( $thumb_path );
$big_image_path = $doc->createElement("big_image_path");
$big_image_path->appendChild(
$doc->createTextNode( $fullimage["imageload"] )
);
$b->appendChild( $big_image_path );
$description_text = $doc->createElement("description_text");
$description_text->appendChild(
$doc->createTextNode( $imagetext["description"])
);
$b->appendChild( $description_text );
$r->appendChild( $b );
$doc->save("load/config.xml");
The XML file parmeters should look like this:
load/thumbs/18.jpgload/images/18.jpgDog Image
The code I currently have produces this:
Thumbnail file name from class.upload.phpFull image file name from class.upload.phpGirls
include('class.upload.php'); $filehandler = new upload($_FILES['image_field']); if ($filehandler->uploaded) { // save uploaded image with no changes $filehandler->file_overwrite = true; $filehandler->Process('load/images/'); if ($filehandler->processed) { echo 'original image copied'; } else { echo 'error : ' . $filehandler->error; } // save uploaded image with a new name, // resized to 160px height // $filehandler->file_new_name_body = 'image_resized'; //$filehandler->image_convert = jpg; $filehandler->image_resize = true; $filehandler->file_overwrite = true; $filehandler->image_y = 160; $filehandler->image_ratio_x = true; $filehandler->Process('load/thumbs/'); if ($filehandler->processed) { echo 'image renamed, resized y=160 and converted to JPG'; $filehandler->Clean(); } else { echo 'error : ' . $filehandler->error; } } $thumbimage = array( 'thumbnail' => 'Thumbnail file name from class.upload.php',); $fullimage = array( 'imageload' => 'Full image file name from class.upload.php',); $imagetext = array( //Can still use description parameter from form in index php file 'description' => $_POST['description_text'],); $doc = new DOMDocument(); $doc->load( 'load/config.xml' ); $doc->formatOutput = true; $r = $doc->getElementsByTagName("settings")->item(0); $b = $doc->createElement("image"); $thumb_path = $doc->createElement("thumb_path"); $thumb_path->appendChild( $doc->createTextNode( $thumbimage["thumbnail"] ) ); $b->appendChild( $thumb_path ); $big_image_path = $doc->createElement("big_image_path"); $big_image_path->appendChild( $doc->createTextNode( $fullimage["imageload"] ) ); $b->appendChild( $big_image_path ); $description_text = $doc->createElement("description_text"); $description_text->appendChild( $doc->createTextNode( $imagetext["description"]) ); $b->appendChild( $description_text ); $r->appendChild( $b ); $doc->save("load/config.xml");The XML file parmeters should look like this:
The code I currently have produces this: