Jump to content

Displaying Files, From File Upload


ChompGator

Recommended Posts

Hello,

 

I recently developed a PHP script that allows users to upload files into a MySQL database.

 

My next step is having a PHP page that shows the files by

ID | File Name

 

And the File Name should be linked to the file so when a user clicks on the file name, it starts downloading the file....

 

Ive tried doing it a few different ways, but none of my methods seem to work...I was wondering if anyone had any advice (my script is below, and the script that inserts the file into the db)

This script does not link the file name to the file, I couldn't seem to get that part to work!

 

Thanks

Display.php

<?php
// Connects to your Database
mysql_connect("", "", "") or die(mysql_error());
mysql_select_db("Database_Name") or die(mysql_error());
$data = mysql_query("SELECT * FROM uploads")
or die(mysql_error());
Print "<table border cellpadding=3>";
while($info = mysql_fetch_array( $data ))
{
Print "<tr>";
Print "<th>ID:</th> <td>".$info['id'] . "</td> ";
Print "<th>File Name:</th> <td>".$info['filename'] . " </td></tr>";
}
Print "</table>";
?>

 

 

Insert-Into-Db.php

<?php 
mysql_connect("","",""); 
mysql_select_db(""); 
$data = addslashes(fread(fopen($form_data, "r"), filesize($form_data))); 
$result=MYSQL_QUERY("INSERT INTO uploads (description, data,filename,filesize,filetype) ". "VALUES ('$form_description','$data','$form_data_name','$form_data_size','$form_data_type')"); 
$id= mysql_insert_id(); 
print "<p>File ID: <b>$id</b><br>"; 
print "<p>File Name: <b>$form_data_name</b><br>"; 
print "<p>File Size: <b>$form_data_size</b><br>"; 
print "<p>File Type: <b>$form_data_type</b><p>"; 
print "To upload another file"; 
?>

Link to comment
https://forums.phpfreaks.com/topic/139807-displaying-files-from-file-upload/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.