The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
Downloading from mysql databse
Discuss Downloading from mysql databse in the PHP Development forum on Dev Shed. Downloading from mysql databse PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

November 20th, 2012, 01:40 AM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 2
Time spent in forums: 45 m 41 sec
Reputation Power: 0
|
|
Downloading from mysql databse
hey pros, i have a problem with my download.php page i have a database with a table that stores pdf files and these files are displayed on the files page and want users to download them
|

November 20th, 2012, 02:08 AM
|
|
|
Quote: | Originally Posted by odongo hey pros, i have a problem with my download.php page i have a database with a table that stores pdf files and these files are displayed on the files page and want users to download them |
So what problem are you having and what is the relevant code causing the problem???
|

November 20th, 2012, 09:40 AM
|
 |
Likely to be eaten by a grue.
|
|
Join Date: Oct 2006
Location: Pennsylvania, USA
|
|
|
Yeah...what's the problem here? You list files and you want to make them clickable? Do that, see what happens. Look into readfile() and the header() function to send the appropriate file headers for PDFs (google will help with that)
__________________
HEY! YOU! Read the New User Guide and Forum Rules
"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin
"The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002
Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
|

November 22nd, 2012, 06:49 PM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 2
Time spent in forums: 45 m 41 sec
Reputation Power: 0
|
|
|
here is the code
$fileId = $_GET["fileId"];
$sql = "SELECT File_Type, File_Name, File_Size, File_Bytes FROM exams WHERE File_ID = ?";
$dsn = 'mysql:dbname=fred;host=localhost;port=3306';
$user = 'root';
$password = '';
try {
$dbh = new PDO($dsn, $user, $password);
$stmt = $dbh->prepare($sql) or die (implode(':', $stmt->errorInfo()));
$stmt->bindParam(1, $fileId, PDO::PARAM_INT, 60);
$stmt->execute() or die (implode(':', $stmt->errorInfo()));
$row = $stmt->fetch();
header("Content-type: $row[0]");
header("Content-length: $row[2]");
header("Content-disposition: attachment; filename=$row[1]");
print $row[3];
} catch (PDOException $e) {
die ('Connection failed: '.$e->getMessage());
}
?>
|

November 22nd, 2012, 07:03 PM
|
 |
Contributing User
|
|
Join Date: Sep 2002
Location: Seattle, U.S.A.
Posts: 712
 
Time spent in forums: 4 Days 11 h 4 m 59 sec
Reputation Power: 11
|
|
|
Are you getting an error message? Also wrap code with the php tags.
|

November 22nd, 2012, 07:21 PM
|
|
Contributing User
|
|
Join Date: Jun 2009
Posts: 295
  
Time spent in forums: 3 Days 8 h 35 m 37 sec
Reputation Power: 5
|
|
|
Just a total guess... Is your SQL statement supposed to end as "WHERE File_ID = ?". It seems your '?' should be replaced with your $fileId value.
|

November 22nd, 2012, 09:27 PM
|
 |
Likely to be eaten by a grue.
|
|
Join Date: Oct 2006
Location: Pennsylvania, USA
|
|
|
try/catch only catches exceptions. PDO doesn't throw an exception when a query fails. You need to handle the errors yourself.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|