Upload profile picture using php

Hi All! Ok, I am in the process of setting up a profile based site, its all gone ok, but I am just getting stuck on letting a user upload images to their profile. I am using php with mysql, and basically just want to let the user upload images so they will have one main image (next to their name in search results etc) then more pictures within their profile in form of a gallery (hopefully automatically resizing photos if to large, and creating thumbnails etc). I have had a look around the site, and others, but cannot seem to find anything, but I do apologize if this topic has already been covered! If anyone can give me any starters, places to get code, even a good book they could recommend I would be very greatful! All the best,

Mike :slight_smile:

ps, I am currently thinking its best to put the photo into mysql, however some people say its better to store only the name in the db and the file itslef elsewhere (however I still dont know how to do this!lol!) Thanks again

If you store the image in MySQL you will need a php servlet that communicates with MySQL to serve the image. On the other hand if the image is stored as a file all php/MySQL needs to do is produce an <img> tag.

I think the difficult bit he is looking to achieve is uploading images to the server from the clients machine. 'Fraid I don’t know enough to help though.

quick search of the php forum gives plenty of resources and answers :slight_smile:

Spike

Hi again!! Thanks for the help!!! Yes I am looking through everything, but just cannot seem to find one that is what I need. I have used one of the site point books, (build your own database driven website using php and mysql if any of you know it… :slight_smile: ). But I have come across two problems which I just cannot figure out! the first is just displaying the images, currently I can only see the file name, which I then click to see the image (I want to be able to get just a thumbnail), the second is then having it so each user has their own images on their own profile (however I think I may be able to crack this if i can get the image displaying sorted!!!). I am not sure if I am making this a lot harder than it actualy is, can anyone think of just a much simplar way to do this? (using something like java or anything…), Thanks again in advance!!

Alright i have a script for you man and Good luck on your site, im creating something like a myspace lol. this is a multi uploader you will have to edit just a little bit to make it is set to your limit and some security on it.

Processfiles.php

<?
$uploadNeed = $_POST[‘uploadNeed’];
// start for loop
for($x=0;$x<$uploadNeed;$x++){
$file_name = $_FILES[‘uploadFile’. $x][‘name’];
// strip file_name of slashes
$file_name = stripslashes($file_name);
$file_name = str_replace(“'”,“”,$file_name);
$copy = copy($_FILES[‘uploadFile’. $x][‘tmp_name’],$file_name);
// check if successfully copied
if($copy){
echo “$file_name | uploaded sucessfully!<br>”;
}else{
echo “$file_name | could not be uploaded!<br>”;
}
} // end of loop
?>

Uploadform1.php

<html>
<head>
<title># of Files to Upload</title>
<meta http-equiv=“Content-Type” content=“text/html; charset=iso-8859-1”>
</head>

<body>
<form name=“form1” method=“post” action=“uploadForm2.php”>
<p>Enter the amount of boxes you will need below. Max = 9.</p>
<p>
<input name=“uploadNeed” type=“text” id=“uploadNeed” maxlength=“1”>
</p>
<p>
<input type=“submit” name=“Submit” value=“Submit”>
</p>
</form>
</body>
</html>

Uploadform2.php

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv=“Content-Type” content=“text/html; charset=iso-8859-1”>
</head>

<body>

<form name=“form1” enctype=“multipart/form-data” method=“post” action=“processFiles.php”>
<p>
<?
// start of dynamic form
$uploadNeed = $_POST[‘uploadNeed’];
for($x=0;$x<$uploadNeed;$x++){
?>
<input name=“uploadFile<? echo $x;?>” type=“file” id=“uploadFile<? echo $x;?>”>
</p>
<?
// end of for loop
}
?>
<p><input name=“uploadNeed” type=“hidden” value=“<? echo $uploadNeed;?>”>
<input type=“submit” name=“Submit” value=“Submit”>
</p>
</form>
</body>
</html>

Hope it works for you Best of luck

Awsome, thanks Jordan! Good luck with your site! Are you going to upload you pictures and keep a path to it in a db? I am just trying to get my head around uploading the picture to a certain path, then add the path to my db along with the user id etc. ( if you know any good scripts please shout! :slight_smile: ). Then I am planning on showing the picture in the profile with a type of picture/thumbnail thing, something along the lines of

<img src=“<%=MyRecordset(“ImageUrl”)%>” alt=“<%=MyRecordset(“ImageDescription”)%>” />

Is this somthing similar to what you are doing? If you know of a better way of doing it or somthing please say so!!

PHP Upload single file
http://www.phpeasystep.com/workshopview.php?id=1

In tutorial doesn’t keep in db. If you wan to kepp in DB just
keep variable name “$path” into DB, it’s a path and file name.

if you want to echo image
use this syntax


$sql="SELECT * FROM table";
$result=mysql_query($sql);
while($rows=mysql_fetch_array($result)){
<img src="<? $rows['image_column']; ?>">