Php code for downloading a file from database - suggest
Php code for downloading a file from database - remarkable, rather
![php code for downloading a file from database php code for downloading a file from database](http://www.nusphere.com/graphics/php_db/php-database.png)
how to download the files stored in database using php
|
✓ answered by Atli
Hi.
The error that is showing tells us exactly why the code is failing: . The file path you are passing to the function is invalid, so PHP can't send it to you.
You say this is a file "from database". Do you mean that the file is stored in the database, like I do in the tutorial you originally posted in, or is the file on the file system and it's location in the database? (The latter is what you usually do, and what you should usually do.)
If the file is inside the database, then what you are doing there makes no sense. Look at phase #4 in the tutorial for an example of what you should be doing.
If the file is on the file-system, then there are steps you must take before trying to send it. First of all, you need to verify that the file actually exists before you try to read it. For that, the file_exists function can be used. You should never attempt to send a file without using that function to make sure it exists.
Also, as with all user input, you should verify that values exist before you use them. If your code depends on a value being present, you need to use isset() or empty() to make sure that it really exists, and/or that it actually has a value. (The isset() function only verifies the former, while empty() verifies both.)
The error that is showing tells us exactly why the code is failing: . The file path you are passing to the function is invalid, so PHP can't send it to you.
You say this is a file "from database". Do you mean that the file is stored in the database, like I do in the tutorial you originally posted in, or is the file on the file system and it's location in the database? (The latter is what you usually do, and what you should usually do.)
If the file is inside the database, then what you are doing there makes no sense. Look at phase #4 in the tutorial for an example of what you should be doing.
If the file is on the file-system, then there are steps you must take before trying to send it. First of all, you need to verify that the file actually exists before you try to read it. For that, the file_exists function can be used. You should never attempt to send a file without using that function to make sure it exists.
Also, as with all user input, you should verify that values exist before you use them. If your code depends on a value being present, you need to use isset() or empty() to make sure that it really exists, and/or that it actually has a value. (The isset() function only verifies the former, while empty() verifies both.)
Expand|Select|Wrap|Line Numbers
- if (!empty($_GET["filename"])) {
- // Proceed with the script.
- }
- else {
- echo "You must pass a file name if you want to download a file!";
- }
|
|
![](https://bytes.com/images/sidecolumn.gif)
-
-
-