Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Crop multiple images one at a time with JCrop and session in php

I have an image crop script that crops one image at a time using the Jquery Jcrop plugin. now I want to upload more images and crop them one by one using a for loop.

What is the best way to do this?

I set my input field to multiple so it could upload more than one.

EDIT:

I've editted my code below with a $max and count. and I think I'm doing it wrong. how can I fix it so when I click crop, it crops them after each-other.

This is my uploaded.php:

    <?php 
         session_start();
         $max = count($_FILES['userfile']['name']);
         for($i = 0; $i < $max; $i++){
            $target = $_FILES['file'][$i];
         }

         $target = "data/uploads/"; 
         $target = $target . basename( $_FILES['filename']['name']) ; 
         $_SESSION['target_path'] = $target;

         $ok=1; 
         if(move_uploaded_file($_FILES['filename']['tmp_name'], $target)) 
         {
             echo "De afbeelding *". basename( $_FILES['filename']['name']). "* is geupload naar de map 'uploads'";
         } 
         else 
         {
             echo "Sorry, er is een probleem met het uploaden van de afbeelding.";
         } 
    ?> 

Thanks!

like image 200
Kees Sonnema Avatar asked Nov 03 '22 02:11

Kees Sonnema


1 Answers

You need to check a few things

1) To upload files, read: http://php.net/manual/en/features.file-upload.multiple.php - specifically input name="userfile[]" in HTML and files on server show up as $_FILES['userfile']['name'][0],...,$_FILES['userfile']['name'][N]

2) move_uploaded_file() is a security check to ensure files are valid, dont leave home without it :-)

3) I'd recommend imagemagick library (http://php.net/manual/en/imagick.cropimage.php), I know, Jcrop demo uses GD library but worth your time looking at imagemagick.

4) Lastly if all fails, use print_r($variable) to ensure the files are getting into your server.

5) Sometimes it could be system admin issue like unwritable /tmp folder, disk full, upload size limit in php.ini and web server built-in timeout. Checking phpinfo() helps too

like image 64
Alvin K. Avatar answered Nov 09 '22 05:11

Alvin K.