Hello, In my app, the user is able to upload images. I'm trying that,
when the user leaves my page without "saving" (to dababase), if images
were uploaded delete them. With javascript event window.onbeforeunload
i'm doing an ajax call just before user leaves.

function onWindowLeave(){
        if(uploadedImgs.length > 0){
                var ids = [], tmp;
                jQuery.each(uploadedImgs, function(index, obj){
                        tmp = obj.dbURL;
                        tmp = tmp.substr(tmp.lastIndexOf("/") + 1);
                        ids[index] = tmp;
                });
                var _url = upload_url.replace("images/upload", "images/
delete_files/" + ids.join(","));
                jQuery.ajax({
                        type: "POST",
                        url: _url
                });
        }
}window.onbeforeunload = onWindowLeave;

My Controller does the following

function delete_files($fileNames){
        if(!empty($fileNames) && $this->RequestHandler->isAjax()){
                $filesPath = WWW_ROOT . 'files' . DS . 'user_uploaded_imgs' . 
DS;
                $fileNames = explode(",", $fileNames);
                foreach($fileNames as $fileName){
                        unlink($filesPath . $fileName); // Delete each file
                }
        }
        $this->layout = null;
}

I added this line in AppController $this->Auth->allowedActions =
(...,'delete_files'); when I leave the page, it all executes
correctly, but my session ends.
Before adding this line delete_files() was not being executed but my
session is not terminated. After several reloads, delete_files()
executes and again session is terminated.
Someone has any idea?

Thanks a lot

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to