Hello all,
I am trying to code for user's profile pic uploading and resizing the image.
I am using the following code and I dont know where I am going wrong!
<?php
//This is the directory where images will be saved
$target1 = "images/";
$target = $target1 . basename( $_FILES['photo']['name']);
//This gets all the other information from the form
$name=$_POST['name'];
$pic=($_FILES['photo']['name']);
// Connects to your Database
database connections
//Writes the information to the database
mysql_query("INSERT INTO `example` VALUES ('$name', '$pic')") ;
//Writes the photo to the server
if(move_uploaded_file($_FILES['photo']['tmp'], $target))
{
//Tells you if its all ok
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
}
else {
echo $_FILES['photo']['tmp'];
echo "Sorry, there was a problem uploading your file.";
}
$data = mysql_query("SELECT * FROM example")
or die(mysql_error());
while($info = mysql_fetch_array( $data ))
{
//Outputs the image and other data
echo "<b>Name:</b> ".$info['name'] . "<br> ";
echo "<img src=http://www.websitename.com/images/".$info['photo'] ."> <br>";
}
?>
Whats happening here is name and image name are getting stored in the database but nothing is stored in the images folder in the server. I am not getting the image displayed .
Can anyone suggest whats the exact method if the below code is wrong somewhere. Also any suggestions about how to resize the image uploaded.
Thank you in advance.