Welcome Guest! You need to login or register to make posts.

Notification

Icon
Error

Options
Go to last post Go to first unread
PatrickTT  
#1 Posted : Sunday, April 10, 2011 7:59:30 PM(UTC)
PatrickTT

Rank: Newbie

Groups: Member
Joined: 4/7/2011(UTC)
Posts: 9

Hi everyone,

I have spent a lot of time trying to integrate the ImageUploader 7 with CakePHP 1.3 and I think I am so close, but just can't seem to get it.

I currently have got as far as displaying it in the view, and it calls the upload function and puts all the files into the one folder.

However, I need a bit more flexibility than that, so I am using the UploadHandler code as follows:

Code:
$handler = new UploadHandler();
$handler->setFileUploadedCallback('saveUploadedFile');
$handler->setAllFilesUploadedCallback('saveAllUploadedFiles');
$handler->processRequest();


I have 2 functions in the controller class to correspond with saveUploadedFile and saveAllUploadedFiles.

Problem is, they don't seem to run at all. I have tried updating it to 'GalleryAlbumsController::saveUploadedFile' etc and that still doesn't work. How can I set a function in the GalleryAlbumsController class to be the callback function?

Any help would be greatly appreciated.

Thanks

Patrick

Edited by moderator Sunday, April 10, 2011 8:19:58 PM(UTC)  | Reason: Not specified

Dmitry.Obukhov  
#2 Posted : Tuesday, April 12, 2011 12:07:07 AM(UTC)
Dmitry.Obukhov

Rank: Advanced Member

Groups:
Joined: 5/29/2010(UTC)
Posts: 1,310

Thanks: 8 times
Was thanked: 111 time(s) in 111 post(s)
Patrick,

Please read Saving Uploaded Files in PHP article and look at example of callback function.
Best regards,
Dmitry Obukhov
Technical Support. Aurigma, Inc.
PatrickTT  
#3 Posted : Tuesday, April 12, 2011 3:38:18 AM(UTC)
PatrickTT

Rank: Newbie

Groups: Member
Joined: 4/7/2011(UTC)
Posts: 9

Hi Dmitry, I have read that, but because it is within CakePHP, the function which sets the

$handler->setFileUploadedCallback("saveUploadedFile");
$handler->setAllFilesUploadedCallback("saveAllUploadedFiles");

is inside a class. So my issue is what I need to actually put in the brackets to call the function?

for example,

Code:
class GalleryAlbumsController extends AppController {

function upload() {
$handler = new UploadHandler();
$handler->setFileUploadedCallback("saveUploadedFile");
$handler->setAllFilesUploadedCallback("saveAllUploadedFiles");
$handler->processRequest();
}

function saveUploadedFile($uploadedFile){
...
}

function saveAllUploadedFiles($uploadedFiles) {
...
}

}


That's pretty much what I have, but nothing I put in those functions runs. I'm sure it's just a scope thing probably but I have tried so many options and nothing seems to work...

Any help would be great.. :)
andreym  
#4 Posted : Tuesday, April 12, 2011 7:07:03 PM(UTC)
andreym

Rank: Advanced Member

Groups:
Joined: 6/16/2009(UTC)
Posts: 134

Was thanked: 8 time(s) in 8 post(s)
Hi Patrick!

In case you didn't read yet, there are some good information about callbacks on php.net web site. The example of how to use object methods as a callback is there.
In short, instead of passing string with function name, you need to pass the array of two elements: the object instance and the method name.

Code:
class GalleryAlbumsController extends AppController {

function upload() {
$handler = new UploadHandler();
$handler->setFileUploadedCallback(array($this, "saveUploadedFile"));
$handler->setAllFilesUploadedCallback(array($this, "saveAllUploadedFiles"));
$handler->processRequest();
}

public function saveUploadedFile($uploadedFile){
...
}

public function saveAllUploadedFiles($uploadedFiles) {
...
}

}


Hope it will help. Please try it and reply if it works for you. Thanks.
PatrickTT  
#5 Posted : Wednesday, April 13, 2011 12:08:36 AM(UTC)
PatrickTT

Rank: Newbie

Groups: Member
Joined: 4/7/2011(UTC)
Posts: 9

ahhhh that looks like what I need... ok I will try that and post back if that works...

:)

andreym you are a legend :D thank you soooooo much :D so nice to be able to do things the right way within CakePHP. has been a very long and difficult learning curve to get this all integrated with cake, but definitely worth it.

thanks again :)

Edited by user Monday, April 25, 2011 5:49:11 AM(UTC)  | Reason: Not specified

Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.