Jump to content

[SOLVED] storing files in db


ROCKINDANO

Recommended Posts

right, acctually thats how i have it right now. but these are pdf's that are being listed weekly. so every time they put one in a folder i have to input a new record in a db. so i was thinking of having the files uploaded to db that way everytime that they do upload it produces a new link on the page with the current pdf.

 

anyways, i guess ill keep it as i have it. but what would be one disadvantage of storing them in a db?

right, acctually thats how i have it right now. but these are pdf's that are being listed weekly. so every time they put one in a folder i have to input a new record in a db. so i was thinking of having the files uploaded to db that way everytime that they do upload it produces a new link on the page with the current pdf.

 

anyways, i guess ill keep it as i have it. but what would be one disadvantage of storing them in a db?

 

you can still have that...just have the upload move the PDF to the folder, and create a record in the database. the record would contain general info (filename, who uploaded it, when they uploaded it, etc) not the actual contents of the file

 

i've just had lots of troubles with reading/writing the data, and performance problems when the files start getting big. i haven't done much with MySQLi though, which I think you can bind a field to a file handle for the INSERT. with the regular mysql functions you are supposed to base64 encode the data, then make a GIANT string for the INSERT query, then execute it

well this is what i have:

 

uploadform.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>upload pdfs</title>
</head>

<body>
<form action="uploadpdf.php" enctype="multipart/form-data" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="51200" />
<p>File to upload:
<input type="file" name="fileupload" /></p>
<p><input type="submit" value="upload!" /></p>
</form>
</body>
</html>

 

uploadpdf.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>uploading file</title>
</head>

<body>
<?php
$file_dir = "pdfs\\citysect\\";

foreach ($_FILES as $file_name => $file_array)
{
	print "path: ".$file_array['"tmp_name"']. "<br />";
	print "name: ".$file_array[''"name"]."<br />";
	print "type: ".$file_array["'type'"]."<br />";
	print "size: ".$file_array[''"size"]."<br />";


	if (is_uploaded_file($file_array['"tmp_name"'])) {
		move_uploaded_file($file_array['"tmp_name"'],
			"$file_dir\".$file_array["name"]") or die ("could not moved");
			print "file was moved!<br />";
	}
}


?>
</body>
</html>

 

but its not uploading!!! can't see the error 

 

help!

try

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>uploading file</title>
</head>

<body>
<?php
   $file_dir = "pdfs/citysect/";
   $file= $_FILES['fileupload'];
   print "path: ".$file['tmp_name']. "<br />";
   print "name: ".$file['name']."<br />";
   print "type: ".$file['type']."<br />";
   print "size: ".$file['size']."<br />";
   print "error: ".$file['error']."<br />";
      
   if (is_uploaded_file($file['tmp_name'])) {
     move_uploaded_file($file['tmp_name'],"$file_dir/".$file['name']) or die ("could not moved");
     print "file was moved!<br />";
   }
?>
</body>
</html>

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.