Jzzt Posted May 4, 2006 Share Posted May 4, 2006 Hi,first of all I'm dutch so if my english isn't perfect I apologize.Second of all I haven't got much experience with php so my question is probably (and hopefully) easy to answer.Here's the case:in my website I want the webmaster to easily upload pictures and add a discription to them.I have a script that uploads pictures to my webserver and it works. You can see the code below:<form name="form1" method="post" action="" enctype="multipart/form-data"> <input type="file" name="imagefile"> <br> <input type="submit" name="Submit" value="Submit"> <? if(isset($_POST['Submit'])) { //If the Submitbutton was pressed do: if ($_FILES['imagefile']['type']=="image/pjpeg" || $_FILES['imagefile']['type']=="image/gif"){ // MAKE SURE THERE EXIST A FOLDER NAMED 'files' IN THIS PAGE'S CURRENT DIRECTORY // Actually you don't have to supply a folder, it will upload the files to current directory // but for easier and safer file handling, it will be wise to set a separate directory for uploaded files // and this is just an example, you can set '../File/' so that it will jump to another directory altogether. // For Windows users, there will be no problem, but for unix-based users, CHMOD 777 to the upload folder! $imglink = "files/".$_FILES['imagefile']['name']; copy ($_FILES['imagefile']['tmp_name'], $imglink) or die ("Could not copy"); echo "<br>Name: ".$_FILES['imagefile']['name'].""; // the file name+extension echo "<br>Size: ".$_FILES['imagefile']['size']."bytes"; // the size in bytes echo "<br>Type: ".$_FILES['imagefile']['type'].""; // the file type echo "<br><img src=".$imglink." height=50 width=50><br>"; // view the uploaded file/image with fixed height and width } else { echo "<br><br>"; echo "Could Not Copy, Wrong Filetype (".$_FILES['imagefile']['name'].")<br>"; } } ?></form>Now all I need to do is write the filename to a database. I would like to use a ms access database.Can anyone help me please??Thnx a lot!Jzzt Quote Link to comment https://forums.phpfreaks.com/topic/9088-how-to-save-filenames-into-a-database/ Share on other sites More sharing options...
prodynetech Posted May 6, 2006 Share Posted May 6, 2006 I am unfamilliar with PHP->MS Access database solutions, but I am able to show you how to access, store, and read from MySQL, PostgreSQL, MSSQL databases using php.First thing you need to do is create a connection to the database:MYSQL:$link = @mysql_connect( DB_SERVER, DB_SERVER_USERNAME, DB_SERVER_PASSWORD ) ;MSSQL:$link = @mssql_connect( DB_SERVER, DB_SERVER_USERNAME, DB_SERVER_PASSWORD ) ;POSTGRESQL:$link = pg_connect( "host=".DB_SERVER." port=".DB_SERVER_PORT." dbname=".DB_NAME." user=".DB_SERVER_USERNAME." password=".DB_SERVER_PASSWORD ) ; Once you have a successful connection to the database, you can start giving SQL queries to it. For example:$sql = "SELECT * FROM uploaded_files WHERE filename='%abc%' ;$resource = mysql_query( $sql, $link ) ;$result_array = @mysql_fetch_array( $resource ) ;Now, to add a record to a database table you would use a query statement like:$sql = "INSERT INTO uploaded_files VALUES( NULL, '".$file_name."', '".file_size."', '".file_description."'" ;$resource = mysql_query( $sql, $link ) ;If you would like to update a record you would use:$sql = "UPDATE uploaded_files SET file_name='".$file_name."', file_size='".$file_size."', file_description='".$file_description."' WHERE file_id=5" ;$resource = mysql_query( $sql, $link ) ;There is a lot more to PHP/Database routines, so I suggest you read www.php.net and any other PHP/MySQL, PHP/MSSQL, or PHP/PostgreSQL resource you can find on the Internet (a google search does wonders).If you would rather go the MS Access route I apologize for be unable to assist you.Best Regards,ProdyneTech[!--quoteo(post=371391:date=May 4 2006, 06:41 PM:name=Jzzt)--][div class=\'quotetop\']QUOTE(Jzzt @ May 4 2006, 06:41 PM) [snapback]371391[/snapback][/div][div class=\'quotemain\'][!--quotec--]Hi,first of all I'm dutch so if my english isn't perfect I apologize.Second of all I haven't got much experience with php so my question is probably (and hopefully) easy to answer.Now all I need to do is write the filename to a database. I would like to use a ms access database.Can anyone help me please??Thnx a lot!Jzzt[/quote] Quote Link to comment https://forums.phpfreaks.com/topic/9088-how-to-save-filenames-into-a-database/#findComment-33793 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.