Jump to content

[SOLVED] Script to store and then view a file stored in MySQL using PHP


Recommended Posts

I was wondering if there was a simple script to store and the view just a file in MySQL data base using PHP. I just want the file to be stored in the table. I do not want any information about the file stored, but just the data. I have been to a few tutorials that I have been able to locate but nothing has really helped or been what I needed. You guys always have great ideas and I was wondering if anybody could throw some my way? Tips? Tuturials? Anything?

Thanks so much in advance!!

Link to comment
Share on other sites

I apologize, let me make my self a little clearer. I have a pretty firm grasp on storing the File.

Which is done here...



$data = addslashes(fread(fopen($form_data, "r"), filesize($form_data)));

mysql_connect("db", "username", "password") or die(mysql_error());
mysql_select_db("upload") or die(mysql_error());

$query = "INSERT INTO syllabus (teacher, semester, year, course, data) VALUES ('$teacher', '$semester', '$year', '$course', '$data')";

$result = mysql_query($query) or die('Query failed: ' . mysql_error());
Print "Your information has been successfully added to the database.";


Data being my entry for the file. Now My script to display all of this in a table looks like this...


$result = mysql_query("SELECT * FROM syllabus WHERE teacher='$teacher'") or die('Query failed: ' . mysql_error());

echo "<table border='1'>
<th>  ID  </th>
<th>  Name     </th>
<th>  Semester     </th>
<th>  Year     </th>
<th>  Course       </th>
<th>  Syllabus Uploaded  </th>

while($row = mysql_fetch_array($result))
  echo "<tr>";
  echo "<td>" . $row['id'] . "</td>";
  echo "<td>" . $row['teacher'] . "</td>";
  echo "<td>" . $row['semester'] . "</td>";
  echo "<td>" . $row['year'] . "</td>";
  echo "<td>" . $row['course'] . "</td>";
  echo "<td>" . $row['data'] .   "</td>";
  echo "</tr>";
echo "</table>";


However I get this in my table under Syllabus Uploaded.

$sql = 'INSERT INTO `teacher` (`id`, `fname`, `lname`) VALUES ('''', ''Hope'', ''ThisWorks'')'; $sql = 'INSERT INTO `teacher` (`id`, `fname`, `lname`) VALUES ('''', ''John'', ''Doe'')';


Anybody have any advice?

Link to comment
Share on other sites

O wow, Stupid mistake on my part. When I said I was getting this...

$sql = 'INSERT INTO `teacher` (`id`, `fname`, `lname`) VALUES ('''', ''Hope'', ''ThisWorks'')'; $sql = 'INSERT INTO `teacher` (`id`, `fname`, `lname`) VALUES ('''', ''John'', ''Doe'')';


Printed out in my data column. It was the acutaul contents of the text file that I uploaded...

Now that I have made a complete fool out of myself.


Does anyone have any ideas on what I can display in the "data" part of my table. I do not want it to print out what is in the file. Perhaps just give an indication that there is something uploaded?


Also, Is there an easy way to download the file that I have uploaded into the "data" field in my database?

THanks again,

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.

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.