This topic is locked

Download Files (From A Blob Field)

5/2/2013 2:32:01 PM
PHPRunner General questions
D
Domenico Giacchero author

I have a a PARENT file and a CHILD one (relation on the fieldid)

There is a blob field in each record of CHILD that ca contain mostly a doc or pdf or jpg file.

In the list page there is the possibility of downloading them ONE by ONE.

I would like to download all the files belonging to all the records of CHILD file.

Is there the possibility to do that?

Maybe using some code (?) in a separeted button?

THank you

C
cgphp 5/2/2013

You need custom code. You can create a zip file on the fly to collect the files belonging to all the records of CHILD file.

D
Domenico Giacchero author 5/2/2013



You need custom code. You can create a zip file on the fly to collect the files belonging to all the records of CHILD file.



Any suggestion?

C
cgphp 5/2/2013
D
Domenico Giacchero author 5/2/2013



Check this link: http://davidwalsh.name/create-zip-php



OK Thank you, I take a look to that link and I found it very interesting, and it is not a problem to retrieve the files name fron the DB.

But for the above problem, if I need to download 'EVERY' file (without making a ZIP ?

C
cgphp 5/2/2013

I'm not sure I understand what you mean. Post some screenshots of your app.

D
Domenico Giacchero author 5/3/2013



I'm not sure I understand what you mean. Post some screenshots of your app.



Clicking on 'Download' Button I would like to download all the four files doc_001, ..002,...003, ..004.PDF in client directory.

C
cgphp 5/3/2013

Domenico, the zip solution is the best way. Saving file on the client side requires a confirmation from the user.

D
Domenico Giacchero author 5/3/2013



Domenico, the zip solution is the best way. Saving file on the client side requires a confirmation from the user.



Yes, Ok I understand, but it is the solution I would like to have:

ONE click to download all the files and one confirm for each file to download....

(The user MUST not have to UNZIP the files downloaded)

C
cgphp 5/3/2013

In the "Client after" trigger the click event for each file link using jquery. You have to check the exact path of the links in the DOM.

D
Domenico Giacchero author 5/3/2013



In the "Client after" trigger the click event for each file link using jquery. You have to check the exact path of the links in the DOM.



THank you.

I understand the first paart of your message, but I really no idea how ".... to check the exact path of the links in the DOM."
ANYWAY .... thank you to everybody.

I found the solution I would like to have by myself.

C
cgphp 5/3/2013

Here it is a solution. In the "Client after" tab of the button enter the following code:



var fileArray = new Array();

$('body').append('<iframe src="" id="download-list" style="display:none;" />');
$("td span[id $= '_yourfieldname'] a:first-child").each(function(){

fileArray.push($(this).attr('href'));

});
var i = 0;

var downloadList = $('#download-list');
downloadList.attr('src', fileArray[i]);

i++;
var interval = setInterval(function()

{

if(i < fileArray.length)

{

downloadList.attr('src', fileArray[i]);

i++;

}

else

{

clearInterval(interval);

}

}, 100);


Replace the _yourfieldname string with the real name of the field that stores file names.

For example if the field name is corpo_documento the jquery selector becomes:



$("td span[id $= '_corpo_documento'] a:first-child")