I've got a "download.php" script which serves up files for download and the user can choose to download a ZIP file which is custom to them.. so needs to be generated on the fly.
The problem I've got, is if the user clicks the ZIP file 5 times in quick succession, the ZIP is generated 5 times on the server.
I need a method to only generate this on the first click, and not keep generating over and over again.
I do not want to "disable" the link permanently, because downloading the file again a few minutes later is fine if the user wants to, I just want to try and stop a malicious user hammering the download script to generate ZIPs constantly using server processing power.
Any ideas? I've been trying for hours and can't seem to get a solution which works :/
Thanks
Is it an option to include a captcha code or similar to activate the download? That would stop the fast clicking.
Add jQuery to the front page to disable the button after the first click. Something like:
$("#button").click(fuction(e) {
$(this).attr("disabled", "");
});
Also, you could cache the zip files for a certain amount of time so their only processed once for a thirty minute block, or some time frame.
Related
Using Codeigniter, I'm trying to do something basic.
The site has a form where users upload files for processing. After the files are processed, new files are created and saved in a zip file. Then I use $this->zip->download() to start the download.
But after that I can't do anything to refresh the upload form. And if I reload the view first, the download doesn't work.
All I want to do is upload the files, create the zip, download the zip and wind up with a clean upload form.
Any suggestions how to approach this?
I don't think you will be able to do it on the same page because of missmatched headers. You could try the following: when the zip is ready save it and name it some random/unique id/md5 anything and print the download link in the view with "click here to download your file" with target="_blank" param so it opens in a new tab. (usually browsers are smart enough that it will auto close it when you accept the file). And so you can reset the form in the view as well.
Another way could be with ajax and js i guess but that would be much longer to write.
Ps.: just dont forget to delete the files after x amount of time (if you dont need them)
I have a website which has multiple downloadable videos, Im after a way of limiting the amount of files any user can download at any one time, Currently all users can download all files at once, which is killing speed!
So need to limit to say x2 downloads at once! Is this done in the .htaccess or via php
Thanks
In your download php script make a entry in database table when user hit download process.
As a number of count download hide download button.
I'm creating a website and I'd like to allow users to upload multiple files while they navigate the website.
When the upload completes, it would be nice to have a Javascipt event triggered, to allow the user to specify additional info related to the uploaded files (eg. photo location, tags, etc)
anyway, the required features are:
multiple files allowed for a single upload operation
display an optional progress indicator (at least in the "x of y files uploaded" fashion)
doing it without tying the users to a single page
How can I implement these features?
Any suggestion is greatly appreciated!
Edit
In the event of using a popup window to handle uploads, how can I:
inform the user (on the "master" page) that the upload has completed, or that there have been errors?
(more important) pass the $_FILES array to the popup window? I'd like the user to be able to click "upload" on the main window, or anyway to make the upload start from the main window (eg dragging and dropping files on the main window).
Since navigating the site will switch pages and it's unlikely that there's a full ajax navigation on your site, maybe it could help to somehow upload the files in a second popup window. Not sure how (if) it could be implemented, though, but since you need to upload multiple files at a time I'm afraid you're bound to use flash.
EDIT
So the solution could look like this:
When a user clicks a "select files" button you pop out a new window where he'll be able to actually select files (via flash if multifile upload is necessary). And to notify of upload progress use postMessage. Though postMessage isn't going to work in IE in this case, but probably you could somehow send the message to the server and from the server back to the page.
Another crazy idea is not to use a popup window, but let the user select the files on the page she was first, but once the user selects the files make all the links on the page target=_blank to make any subsequent navigation happen in another tab. I know it's hacky and not exactly user-friendly, but probably could help.
In any case I would inform the user beforehand that a new window will appear in both scenarios.
EDIT2
And an even crazier idea. When the user selects the files and clicks a link create an iframe which will cover the whole page and hide the original page beneath it and make the links open in the iframe. But it looks even more hackish and it seems you'll have much trouble with it.
In a project I'm working on, the client has required that every time a user clicks on a link to download (they will be downloading a video or mp3), there should be a log kept of who has downloaded what and when.
I have a table in my database set up to record the User ID, the File ID, and the date when it was downloaded. However, I don't know how to do this, as the link is basically an tag (obviously).
What is the best way to achieve this?
Probably the simplest solution would be to write simple onclick ajax event.
If you want noscript solution you'll have to create some download wrapper, that'd serve you proper file. Just create special route and controller (eg. /downloads/filename), increment download meter for this one and return asset instead of html response. Don't forget to set proper Content-Type header tho.
There's also IgorwFileServeBundle that could help you loads.
Instead of linking to the MP3 file, you'll have to funnel the download through a PHP script that writes to the database and then sends the MP3 data with with the right headers. For maximum performance use the "X-Sendfile" header instead of the PHP readfile function.
Alternatively you could set up a cron job for a Symfony console command line tool that parses the Apache access log and writes to the DB whenever it encounters an MP3 file.
I have a search page.
On clicking search it will show a jquery modal with processing image and redirect to results page.
I have download functionality also in the search page. If I select the download option,
the result may vary to 1 kb to 25 MB, and I can't put a timer to close the modal window.
Is there any way to find the download is prompted?
Or download is completed? So that I can close modal at that time!!
Just make a popup that disappears when the user click anywhere else, like on github.
It would probably be too much job doing what you requests that it is not worth it. Better just showing a dialog that the user can dismiss whenever s/he wants to.
Well, yes it would be possible to have a script that runs while the file is being served (PHP normally times out within 30sec) and have periodically AJAX-requests to see if download is completed (or aborted).