Donations accepted

Hosted on verot.net

Multiple processes

See all posts Reply

Multiple processes new!
by Leon, 7 years, 2 months ago
Hi Colin,

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
Re: Multiple processes new!
by colin, 7 years, 2 months ago
Do as on the example provided on the main page

$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
Re: Multiple processes new!
by Leon, 7 years, 2 months ago
OK, got it to work, thanks for your help Colin! Colin, may I ask what kind of Captcha you are using?Reply
Re: Multiple processes new!
by colin, 7 years, 2 months ago
The captcha is based on this class, implemented in my homebrew content management system.Reply
Re: Multiple processes new!
by Leon, 7 years, 2 months ago
are you going to release your CMS anytime soon? Nice to see it is multilingual :)Reply
Re: Multiple processes new!
by colin, 7 years, 2 months ago
Sometime soon. Lack of time, etc...Reply
Re: Multiple processes new!
by Leon, 7 years, 2 months ago
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
Re: Multiple processes new!
by colin, 7 years, 2 months ago
Look at the code!

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:
CAPTCHA image
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();
Reply
Re: Multiple processes new!
by Leon, 7 years, 2 months ago
Yes, exactly, the cache problem made me almost sick! Happens almost with every captcha...

I thought of adding a unix timestamp to minimize the problem.Reply