Jump to content

Table to File swap


gavenf

Recommended Posts

Hi there,

 

I have been working on a form to input information into a mysql table along with the files.  I would like to however put the files into a seperate folder on the server. 

 

Here is my code which I have been assisted with already but cannot figure out how to change it to send the actual file to a seperate folder but still keep the information linked so I can recall the file later based on a search of the information in the table.

 

<?php 
mysql_connect("localhost","teacher","slider1234"); 
mysql_select_db("planitteacher"); 
$data = addslashes(fread(fopen($form_data1, "r"), filesize($form_data1))); 
$data2 = addslashes(fread(fopen($form_data2, "r"), filesize($form_data2))); 
$data3 = addslashes(fread(fopen($form_data3, "r"), filesize($form_data3))); 
$result=MYSQL_QUERY("INSERT INTO uploads (description, data,filename,filesize,filetype,title,subject,class,web1,email) ". "VALUES ('$form_description','$data1','$form_data1_name','$form_data1_size','$form_data1_type','$form_title','$form_subject','$form_class','$form_web1','$form_email')");

$result=MYSQL_QUERY("INSERT INTO uploads (description, data,filename,filesize,filetype,title,subject,class,web1,email) ". "VALUES ('$form_description','$data2','$form_data_name2','$form_data_size2','$form_data_type2','$form_title','$form_subject','$form_class','$form_web1','$form_email')");

$result=MYSQL_QUERY("INSERT INTO uploads (description, data,filename,filesize,filetype,title,subject,class,web1,email) ". "VALUES ('$form_description','$data3','$form_data_name3','$form_data_size3','$form_data_type3','$form_title','$form_subject','$form_class','$form_web1','$form_email')");

$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 <a href=http://www.careerposition.org> Click Here</a>"; 
?> 

Link to comment
https://forums.phpfreaks.com/topic/46224-table-to-file-swap/
Share on other sites

Hi gavenf, the problem is..

 

you have the files stored in a blog in a database.. so their is not "folder" involved.

 

i think you will need to either change the upload to actual files&folders or

build a virtual file system with the database..

 

1 question why do you need folder ? and how are the files going to ba accessed ?

Link to comment
https://forums.phpfreaks.com/topic/46224-table-to-file-swap/#findComment-224731
Share on other sites

Hi and thanks for the reply.

 

Ok The db is for some teachers who would like to be able to share lesson plans.  I need to allow them to upload the files along with title, description etc for the lesson.  there may be several files for each lesson plan so I need to be able to make sure the files are related to the lesson plan detials which will be kept in a mysql table. 

 

I have figured out how to get the form to upload information to the table including the file but I cant seem to get the information out.

 

The file is kept in a longblob column.  Problem is I cant figure out what the scrip should be to search the table and return the results so that then the files can be downloaded.

 

I assumed that storing them seperate to the tables would be simpler.  Maybe its not.  thats why I was going to try it a different way.

Link to comment
https://forums.phpfreaks.com/topic/46224-table-to-file-swap/#findComment-224740
Share on other sites

 

Yes It wont rebuild the file.  It looks like a mess of text.

 

How do I get the information out again?

 

so is the problem rebuilding the file after its been added to the database ?

 

if your having problems with the seaching file enties in the databse i would suggest to resolve that first then  deal with the files

Link to comment
https://forums.phpfreaks.com/topic/46224-table-to-file-swap/#findComment-224766
Share on other sites

try

 


<?php
$id=1; //<--set this
mysql_connect("your.server.com","username","password");
mysql_select_db("database_name");
$query = "SELECT data,filetype FROM uploads where id=$id";
$result = MYSQL_QUERY($query);
$data = MYSQL_RESULT($result,0,"data");
$type = MYSQL_RESULT($result,0,"filetype");
Header( "Content-type: $type");
print $data;
?>

Link to comment
https://forums.phpfreaks.com/topic/46224-table-to-file-swap/#findComment-224768
Share on other sites

I tried that.  it only works with pictures not .doc or .pdf files.

 

I need to beable to retrieve all types of files. especially pdf and doc files.

 

Can it be done using a search method of some description?

 

try

 


<?php
$id=1; //<--set this
mysql_connect("your.server.com","username","password");
mysql_select_db("database_name");
$query = "SELECT data,filetype FROM uploads where id=$id";
$result = MYSQL_QUERY($query);
$data = MYSQL_RESULT($result,0,"data");
$type = MYSQL_RESULT($result,0,"filetype");
Header( "Content-type: $type");
print $data;
?>

Link to comment
https://forums.phpfreaks.com/topic/46224-table-to-file-swap/#findComment-224776
Share on other sites

is it too late to change the project to work with 'actual' files ?

 

also try this

 

change

<?php
$query = "SELECT data,filetype FROM uploads where id=$id";

to

<?php
$query = "SELECT data,filetype,filename FROM uploads where id=$id";

 

change

<?php
Header( "Content-type: $type"); ?>

 

to

<?php

header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 

header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=$file");

header( "Content-Description: File Transfer");

?>

 

No idea if it will work

Link to comment
https://forums.phpfreaks.com/topic/46224-table-to-file-swap/#findComment-224778
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.