Jump to content


Photo

Upload Images??


  • Please log in to reply
2 replies to this topic

#1 skatermike21988

skatermike21988
  • Members
  • PipPipPip
  • Advanced Member
  • 100 posts
  • LocationFlorida

Posted 21 March 2006 - 06:28 AM

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 database

so 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?

#2 redbullmarky

redbullmarky
  • Staff Alumni
  • Advanced Member
  • 2,863 posts
  • LocationBedfordshire, England

Posted 21 March 2006 - 08:13 AM

[!--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) View Post[/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 database

so 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:

<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

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

$result = move_uploaded_file($_FILES['my_image_file']['tmp_name'], $newfilepath);

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.
"you have to keep pissing in the wind to learn how to keep your shoes dry..."

I say old chap, that is rather amusing!

#3 lpxxfaintxx

lpxxfaintxx
  • Members
  • PipPipPip
  • Advanced Member
  • 181 posts

Posted 21 March 2006 - 11:40 AM

Currently, my image upload pulls the image out from the db. Heres a sample.

<?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>

Of course, you need to connect to MySQL first. Also, if you don't like the html tags, you can just simple do

echo '<img src="<?php echo $myrow["idpath"]';





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users