Superman911 Posted October 11, 2009 Share Posted October 11, 2009 Hi there. Please could someone help me. I want a page on my site to upload files( PDF, DOC) to a mysql database and the I want to create a link to be able to download it on another page. if someone could help me it would be great! Quote Link to comment Share on other sites More sharing options...
corbin Posted October 11, 2009 Share Posted October 11, 2009 That's a pretty broad question... Do you have trouble with a specific part, or do you not know where to begin? Quote Link to comment Share on other sites More sharing options...
Dorky Posted October 11, 2009 Share Posted October 11, 2009 this would be so much less complicated to just use a folder. im not sure why everything i see in this forum involves sql. Quote Link to comment Share on other sites More sharing options...
Superman911 Posted October 12, 2009 Author Share Posted October 12, 2009 Thanks for the reply. The part I am having problems with is getting the file into mysql and to create a link to download it again. I did try the folder option but also can't get the link to work to download the file then. any pointers will be good! Quote Link to comment Share on other sites More sharing options...
gizmola Posted October 12, 2009 Share Posted October 12, 2009 I would avoid storing blobs in mysql due to the substantial overhead of getting the file data into/out of the database. In essence this is double the overhead of just storing it on the PHP server, although if you have a cluster of servers, this can also become a problem. As for PHP, it uses the $_FILES superglobal to store information about the HTTP post that includes the uploaded file. PHP sticks it in a temp directory, and it's up to you to call move_uploaded_file() and give the file a permanent name and location. Typically this is where people store the location of the file in a database. There's plenty more to be said about this topic, however as for a few tips and places to read, I think this should get you going. Quote Link to comment Share on other sites More sharing options...
Superman911 Posted October 14, 2009 Author Share Posted October 14, 2009 Hey all. I am using the following to upload the files now, but would like to rename the file before saving it, can any body help me with this. <?php if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0) { $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; $fp = fopen($tmpName, 'r'); $content = fread($fp, filesize($tmpName)); $content =addslashes($content); fclose($fp); if(!get_magic_quotes_gpc()){ $fileName = addslashes($fileName); } include 'opendb.php'; $query = "INSERT INTO upload (name, size, type, content ) ". "VALUES ('$fileName', '$fileSize', '$fileType', '$content')"; mysql_query($query) or die('Error, query failed'); echo "<br>File $fileName uploaded<br>"; } ?> Many thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.