AndrewJ1313 Posted July 5, 2008 Share Posted July 5, 2008 Good day. I am attempting to create a script to upload MP3 files to a remote MySQL 4.1.22 database. I wasn't quite sure how to do this so I googled it and came across a few tuturials and have tried following them. Everything appears to work fine, but after the web page has reloaded, the file was not uploaded to the database or anywhere for that matter. I am using PHP 5 and MySQL 4.1.22. Here is the code that I am using in my *.php file: <?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); } $query = "INSERT INTO tbl_sermons (name, size, type, content ) ". "VALUES ('$fileName', '$fileSize', '$fileType', '$content')"; mysql_query($query) or die('Error, query failed'); echo "<br>File $fileName uploaded<br>"; } ?> <form method="post" enctype="multipart/form-data"> <table width="350" border="0" cellpadding="1" cellspacing="1" class="box"> <tr> <td width="246"> <input type="hidden" name="MAX_FILE_SIZE" value="4000000"> <input name="userfile" type="file" id="userfile"> </td> <td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td> </tr> </table> </form> Again, this is code I learned from an online tutorial I came across, if anyone can see what I might have missed or has another suggestion about how to accomplish this I would greatly appreciate it. Cheers, Andrew Link to comment https://forums.phpfreaks.com/topic/113340-uploading-files-to-mysql-using-php/ Share on other sites More sharing options...
thatsgreat2345 Posted July 5, 2008 Share Posted July 5, 2008 You aren't going to be uploading a file to a database what you are going to be doing is uploading then saving the file location to the database. I recommend using move_uploaded_file or some other command which are mainly used for uploads. Link to comment https://forums.phpfreaks.com/topic/113340-uploading-files-to-mysql-using-php/#findComment-582306 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.