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'd first like to resize an uploaded image and copy it to a folder (which I do successfully), then create an image of smaller size to use as a thumbnail and copy it to another folder. I see that I need to use multiple processes over the file loaded to temp folder on server, but I can't figure out how. Can you give an example please?Reply
$foo = new Upload($_FILES['form_field']);
if ($foo->uploaded) {
// save uploaded image with no changes
$foo->Process('/home/user/files/');
if ($foo->processed) {
echo 'original image copied';
} else {
echo 'error : ' . $foo->error;
}
// save uploaded image with a new name
$foo->file_new_name_body = 'foo';
$foo->Process('/home/user/files/');
if ($foo->processed) {
echo 'image renamed 'foo' copied';
} else {
echo 'error : ' . $foo->error;
}
// save uploaded image with a new name,
// resized to 100px wide
$foo->file_new_name_body = 'image_resized';
$foo->image_resize = true;
$foo->image_convert = gif;
$foo->image_x = 100;
$foo->image_ratio_y = true;
$foo->Process('/home/user/files/');
if ($foo->processed) {
echo 'image renamed 'image resized',
resized x=100 and converted to GIF';
$foo->Clean();
} else {
echo 'error : ' . $foo->error;
}
}
So you instantiate the class, then call process() a first time. After the first processing is completed, the variables are reset, so you can set new resizing, etc... options. Then, call process() again.Reply
How do you make it possible to generate another image when clicked on captcha? The original class does not do that. It is probably ajax, can you give some code?Reply
Basically, the source of the image is a PHP script which generates and output the CAPTCHA image (and also set the CAPTCHA phrase into the session). I add a random value to the URL to make sure that the CAPTCHA is generated each time and is not taken from the cache.
See: Replace ### by javascript in the code above.
The file captcha.php is very simple:
session_start();
$captcha = new CaptchaNumbersV2(5);
$captcha->display();
$_SESSION['captcha'] = $captcha->getString();
exit();
I'd first like to resize an uploaded image and copy it to a folder (which I do successfully), then create an image of smaller size to use as a thumbnail and copy it to another folder. I see that I need to use multiple processes over the file loaded to temp folder on server, but I can't figure out how. Can you give an example please?
So you instantiate the class, then call process() a first time. After the first processing is completed, the variables are reset, so you can set new resizing, etc... options. Then, call process() again.
Basically, the source of the image is a PHP script which generates and output the CAPTCHA image (and also set the CAPTCHA phrase into the session). I add a random value to the URL to make sure that the CAPTCHA is generated each time and is not taken from the cache.
See:
Replace ### by javascript in the code above.
The file captcha.php is very simple:
I thought of adding a unix timestamp to minimize the problem.