Jump to content


callback_upload

callback upload pictures

  • Please log in to reply
11 replies to this topic

#1 KaBaDaBrA

KaBaDaBrA

    grocery CRUD magician

  • Members
  • PipPipPip
  • 57 posts

Posted 28 February 2012 - 02:20 PM

Hi,

Since this is my first post I just want to say GROCERYCRUD is insanely awesome and has saved me a lot of time. Really awesome piece of work!

I downloaded the latest files from github and noticed there is a "callback_upload" and "callback_after_upload" callback. Is there an example anyone can show me or how this works. After I uploaded an image I would like to call two custom models I wrote to crop and resize the uploaded images.

Thanks in advance! :D
Grocery CRUD - Categories and Subcategories - Demo and Step by Step here: http://demo.edynamic..._management/add

#2 web-johnny

web-johnny

    grocery CRUD Author

  • Administrators
  • 1,150 posts
  • LocationLondon

Posted 28 February 2012 - 10:11 PM

Hello there and welcome to the forum.

You are lucky as I finished this feature yesterday. Actually in your case you just need the callback_after_upload . So when the upload is done then you need to crop and resize the image. You can do this with a simple callback and the given parameters are:

function test_callback_after_upload($uploader_response , $state_info , $_FILES)
{
   // return  'Your image cannot cropped are you sure that you gicve the right format? '; //return a string for a custom error or false for the default error.
	 return true;// if everything goes fine
}
The callback work exactly the same way as all the callbacks in grocery CRUD so to call it you will just have this simple line of code:
$crud->callback_after_upload(array($this,'test_callback_after_upload'));

For more documentation please wait for the new version. Also I will add the croping resizing functionality at version 1.2 , so if it's not something urgent you can wait till the 23th of March that I have the deadline for my self for the new release.
Posted Image

#3 KaBaDaBrA

KaBaDaBrA

    grocery CRUD magician

  • Members
  • PipPipPip
  • 57 posts

Posted 29 February 2012 - 06:15 AM

Thanks web-johnny and you're LEGEN...wait for it because this pause is just to awesome to give up....DARY!!!!!

I will play around with it today and give it a bash - Currently I have an urgent project to get up, already wrote two models for cropping and resizing so when fails I will just call a manual method for now to check images.

Thanks again!!
Grocery CRUD - Categories and Subcategories - Demo and Step by Step here: http://demo.edynamic..._management/add

#4 web-johnny

web-johnny

    grocery CRUD Author

  • Administrators
  • 1,150 posts
  • LocationLondon

Posted 29 February 2012 - 07:21 AM

Oh I think I found a fan of How I Met Your Mother :D

Thank you for your good words. I really appreciate it.
Posted Image

#5 muonshirata

muonshirata

    Newbie

  • Members
  • Pip
  • 9 posts

Posted 18 April 2012 - 06:08 AM

function resize($uploader_response,$field_info, $files_to_upload){
		$this->load->library('image_moo');
		$file_uploaded = $field_info->upload_path.'/'.$uploader_response[0]->name;
		$thumb = $field_info->upload_path.'/thumbs/'.$uploader_response[0]->name;
		$pic = $this->image_moo->load($file_uploaded);
		$pic->resize(500,300)->save($file_uploaded,true);
		$pic->resize(220,80)->save($thumb,true);
		return true;
	}

hello everyone i have problem to delete 2 image. how i can delete 2 image? because there is no callback to delete a file upload.

#6 web-johnny

web-johnny

    grocery CRUD Author

  • Administrators
  • 1,150 posts
  • LocationLondon

Posted 18 April 2012 - 06:23 AM

As you said for now there is not any callback for delete files. You have to change the library and try to add a callback for the delete. I cannot think about another solution (or workaround) right now.
Posted Image

#7 arif_avi

arif_avi

    Member

  • Members
  • PipPip
  • 12 posts

Posted 17 December 2012 - 12:28 PM

Its highly forbidden to change the core of any libraries else u will seriously face problems while updating ....

heres a solutions ----

Extend the grocery crud model using ur custom class--- (file path -- libraries folder of ci)
<?php
/**
* Description of my_gc
*
* @author Arif
*/
class My_gc extends grocery_CRUD {
	function __construct() {
		parent::__construct();
	}
	
	/**
	 * delete file --- extend parent function and delete the thumbnail
	 * @param object $state_info
	 * @param string $filepath -- eg., /www/my_site/assets/images/
	 */
	protected function delete_file($state_info, $filepath = NULL)
	{
		$result = parent::delete_file($state_info);
		if($result):			
			if($filepath == NULL):
				$upload_info = $this->upload_fields[$state_info->field_name];
				$filepath = $upload_info->upload_path."/thumb_".$state_info->file_name;
			else:
				$filepath = $filepath."thumb_".$state_info->file_name;
			endif;
			
			@unlink($filepath);
			return true;
		endif;
		
		return false;
	}
}

?>


Assuming u are saving ur thumbnail files ase --> thumb_filename.ext

heres what u need to do in ur controller ---


$this->load->library('my_gc');
$crud = new My_gc();


Thanks
ArifAttached File  my_gc.php   979bytes   366 downloads

#8 NewJersey

NewJersey

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 30 September 2013 - 05:28 AM

Is there any easier way to check where to get the file info on a specific field after it was uploaded?

 

I thought of callbacks for upload but not sure if that will do, as it happens aside from the method I am executing when adding a record that contains the file info.

 

I get the the url of the file name on that table, but, that's all...? if I have the $_FILES would be the best in my case.

 

Kind Regards,

 

Ernani



#9 arif_avi

arif_avi

    Member

  • Members
  • PipPip
  • 12 posts

Posted 30 September 2013 - 05:44 AM

Is there any easier way to check where to get the file info on a specific field after it was uploaded?

 

I thought of callbacks for upload but not sure if that will do, as it happens aside from the method I am executing when adding a record that contains the file info.

 

I get the the url of the file name on that table, but, that's all...? if I have the $_FILES would be the best in my case.

 

Kind Regards,

 

Ernani

 

Since GC uses CI's native upload library I guess u should have a look at the $state_info variable which may contain all the values you need(i am not sure though. Will  check once i am free).

More over you could actually use little hack:

1. Use file upload on a field.(so that multipart form type is used)

2. Hide that field using GC'S change field type method.

3. Use callback add field method to add a file field.

4. Then use ur call back on that file field and process the $_Files variable and do what ever you want.

 

Hopefully that will help

Thanks

Arif



#10 NewJersey

NewJersey

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 30 September 2013 - 06:32 AM

Since GC uses CI's native upload library I guess u should have a look at the $state_info variable which may contain all the values you need(i am not sure though. Will  check once i am free).

More over you could actually use little hack:

1. Use file upload on a field.(so that multipart form type is used)

2. Hide that field using GC'S change field type method.

3. Use callback add field method to add a file field.

4. Then use ur call back on that file field and process the $_Files variable and do what ever you want.

 

Hopefully that will help

Thanks

Arif

 

Hello Arif!

 

I was able to use a callback before insert to be able to retrieve the file name of the upload field, with that I was able to read the file bytes and everything else to store it into the db table.

 

It worked like a charm!

 

Thanks!



#11 arif_avi

arif_avi

    Member

  • Members
  • PipPip
  • 12 posts

Posted 30 September 2013 - 06:42 AM

Do share your code with us.

 

Thanks

Arif



#12 HPM

HPM

    Newbie

  • Members
  • Pip
  • 5 posts

Posted 08 June 2015 - 08:12 AM

hello newjersey! can you share your code here







Also tagged with one or more of these keywords: callback, upload, pictures

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users