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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.