skatermike21988 Posted March 21, 2006 Share Posted March 21, 2006 ok i am working on a new members thing on my page and i want users to be able to upload an image to my site and the directory be stored in the databaseso i can do something like this<img src='$image'>Now How Would I Do This So It Uploads It and Then Pulls It From The Databse To Be Displayed? Quote Link to comment Share on other sites More sharing options...
redbullmarky Posted March 21, 2006 Share Posted March 21, 2006 [!--quoteo(post=356873:date=Mar 21 2006, 06:28 AM:name=Skater Mike)--][div class=\'quotetop\']QUOTE(Skater Mike @ Mar 21 2006, 06:28 AM) [snapback]356873[/snapback][/div][div class=\'quotemain\'][!--quotec--]ok i am working on a new members thing on my page and i want users to be able to upload an image to my site and the directory be stored in the databaseso i can do something like this<img src='$image'>Now How Would I Do This So It Uploads It and Then Pulls It From The Databse To Be Displayed?[/quote]without literally going through the entire code, there are 3 things to deal with. first is to set up the <FORM> with the necessary elements:[code]<form action="" method="post" enctype="multipart/form-data" name="form1">...stuff here<input name="imagefile" type="file" id="my_image_file">...more stuff here including a submit button[/code]once the form is submitted, the file is automatically uploaded to the servers temporary directory. to deal with it from their, you need to use the $_FILES superglobal array to get the info you need about the file, and move_uploaded_file to move the file from its temporary location to where you want it to be permanently [code]$result = move_uploaded_file($_FILES['my_image_file']['tmp_name'], $newfilepath);[/code]all you need to do then is use some of the info from the $_FILES['my_image_file'] array to store info in the database for later. - the file size, $_FILES['my_image_file']['size']- the file type, $_FILES['my_image_file']['type']- the original file name, $_FILES['my_image_file']['name']and for error trapping, use $_FILES['my_image_file']['error']in terms of database retrieval, you just pull the filename from the database and put it within the IMG's src.hope that helps. Quote Link to comment Share on other sites More sharing options...
lpxxfaintxx Posted March 21, 2006 Share Posted March 21, 2006 Currently, my image upload pulls the image out from the db. Heres a sample.[code]<?php $imageid= $_GET["id"];$result = mysql_query("SELECT * FROM files WHERE id=$imageid"); $myrow = mysql_fetch_array($result); ?><html><img src="<?php echo $myrow["idpath"];</html>[/code]Of course, you need to connect to MySQL first. Also, if you don't like the html tags, you can just simple do[code]echo '<img src="<?php echo $myrow["idpath"]';[/code] 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.