PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I have modified some code I found on here but am having a problem with it. The file is used to download a file when a link is clicked. I can get the file to start downloading with the correct name & type but not all the file downloads.
I have a column in the DB for the file size, for example 1631613 = 1.6mb. The original script used
Can you clarify.. is it a partial download? Is it close to the required size? I'm encountering a similar problem (only 3 bytes off on zip files). I would filesize() the incomplete download. .and see how much your are off.
You could try the filesize again...just for a test..
if (isset($_GET['id']) && ctype_digit($_GET['id'])){
$id = $_GET['id'];
}
This is cool.. I like the ctype_digit check. I personally don't like to use integers passed in the query. You're open to 'data-mining'.. meaning.. can I try id=6 or 7 or 8 or 9. I don't think this is a 'big' issue with this application. On another note.. you're setting yourself up for for undefined variable if the condition is false. Meaning if I pass id=foo, it'll fail the condition and $id won't be set. I would do the following...
It is only downloading a smal part of the file. I am using a test file that is 567kb, the download only does 25kb and then stops. Moving the filesize() into the header statement makes no difference.
When I do this
the file will download but without saying how large the file is in the dialog box. When the download completes the file will not open saying it is corrupt. Is it because I am getting the filesize from a field in the database. Is there another way of doing this?
Hmm.. that shouldn't work since what is coming out of the DB as an int value, and you're running a filesize() call around that. filesize() takes a full path to the file you want to size.
I'm wondering if it is something with readfile(). I usually do fpassthru(). Can you try this out??