Skip to main content

How can I utilize the upload response when using the jQuery uploader?

Comments

8 comments

  • Andres Vargas

    Hi,

    Is there a way to store this JSON response "data" into a php array so that I can POST it when I submit the form?

    I've been trying and no luck on how to convert this Javascript to PHP.

    0
  • Nadav Ofir

    You can use the identifier that is injected to the form as a hidden field once the upload is done, and send it upon submission. More information is available here: http://cloudinary.com/documentation/php_image_upload#direct_upload_file_tag

    0
  • Andres Vargas

    Yes, I understand thank you.

    Is there anyway to set the hidden field value to the "public_id" value instead?

    I can see hidden field currently sets the value to the image path i.e "image/upload/v1478772086/anzfiijfgtlsuclt9kgz.jpg#84505ad7aa54df14a08f61c144f9e1fa3f899247"

    I think it's better if I could store the public_id in my database instead to apply image transformations easier?

    0
  • Andres Vargas

    I'm guessing the function (cl_form_tag) in the Helpers.php file would have to be modified?

    0
  • Nadav Ofir

    You can use the PreloadedFile class to achieve that separation. E.g.:

    $preloaded = new \Cloudinary\PreloadedFile("image/upload/v1234567890/sample.jpg#abcd");
    echo $preloaded->public_id;

    0
  • Andres Vargas

    Ok thanks.

    I'm actually posting the form as an image[] array because I'm uploading various images at once before I submit the form. I've tried to use the PreloadedFile class but it doesn't accept arrays. Is there a way for it to accept my array of $_POST['image_id']?

    0
  • Nadav Ofir

    Hi Andres,
    PreloadedFile is type that represents a single resource. You'll have to iterate through your uploaded images and parse each one separately.

    0
  • Andres Vargas

    Hi Nadav,
    Thanks for your help! I have been able to succesfully get this running :)

    Here is my code for anyone else needing this.

    < ? php

    echo cloudinary_js_config();

    if(isset($_POST['image_id'] )){

    foreach($_POST['image_id'] as $value){
    $preloaded = new \Cloudinary\PreloadedFile($value);
    if (!$preloaded->is_valid()) {
    echo "Invalid upload signature";
    } else {
    $photo_id = $preloaded->public_id;
    echo "You have uploaded this image: ";
    echo cl_image_tag($photo_id, array("format" => "jpg", "crop" => "fill", "width" => 120, "height" => 80));
    echo " < b r > ";
    }

    }
    }

    ? >

    0

Please sign in to leave a comment.