Jump to content

users profile picture


runnerjp

Recommended Posts

<?php
header('Content-Type: text/plain');
echo "This Page Shows How Uploads Works\n";
print_r($_FILES);
move_uploaded_file($_FILES["profile_image"]["tmp_name"],
  "profileimages/" . $_FILES["profile_image"]["name"]);
if ($_FILES["profileimages"]["error"] > 0)
    {
    echo "Apologies, an error has occurred. Error Code: " . $_FILES["profileimages"]["error"];
    }
else
    {

    move_uploaded_file($_FILES["profileimages"]["tmp_name"],
  "profileimages/" . $_FILES["profileimages"]["name"]);
}
if (($_FILES["profileimages"]["type"] == "image/gif")
  || ($_FILES["profileimages"]["type"] == "image/jpeg")
  || ($_FILES["profileimages"]["type"] == "image/png" )
  && ($_FILES["profileimages"]["size"] < 10000))
  {
  move_uploaded_file($_FILES["profileimages"]["tmp_name"],
    "profileimages/" . $_FILES["profileimages"]["name"]);
  }
else
  {
  echo "Files must be either JPEG, GIF, or PNG and less than 10,000 kb";
  }
?>

 

i have this but how do i add it to my database and a unique id number???

Link to comment
https://forums.phpfreaks.com/topic/50788-users-profile-picture/#findComment-249779
Share on other sites

You don't insert the image into the database, just the path or filename

 

maybe add a new column in the users table called avatar, or image. Then you would insert

profileimages/" . $_FILES["profile_image"]["name"]

into the database. Or if all images are going to be stored in the same place, simply add the filename to the database and when you display their information you simply have variable called

$image_dir='profileimages/';

and concatenate  that variable to the variable pulled out of the database for that user e.g.

 

while($row=mysql_fetch_object($query_variable_here))
{
   $image=$image_dir.$row->avatar;
  // the rest of the while loop here pulling out the other data
}

 

That would give you a path of

 

profileimages/filename.jpg

 

Obviously adjust your paths and such, but that is the basic idea

 

Nate

Link to comment
https://forums.phpfreaks.com/topic/50788-users-profile-picture/#findComment-250369
Share on other sites

so would something like this do

 

<?



//UPLOAD CHECK

$table_name = "$tbl_images";

	$connection = @mysql_connect("$db_host", "$db_user", "$db_pass") or die("Couldn't connect to database.");



	$db = @mysql_select_db($db_name, $connection) or die("Couldn't select database.");



	$sql = "SELECT image_id, directory, url, image	FROM $table_name

	WHERE image_id = \"$comm_id\"

	";



	$result = @mysql_query($sql,$connection) or die("Couldn't execute query.");

	$num=mysql_num_rows($result);



	while ($row = mysql_fetch_array($result)) {



	$image_id = $row['image_id'];

	$directory = $row['directory'];

	$url = $row['url'];

	$image = $row['image'];

	}

	if(isset($image)) {

	$location ="$directory/$image";

	$showimg="../$url/$image";

	?>

Link to comment
https://forums.phpfreaks.com/topic/50788-users-profile-picture/#findComment-250515
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.