can some one help me to implement my upload script, with the following code am able to upload images into database therefore I would like to change/rename the image being uploaded to the user id who is uploading the image as profile picture to avoid file overwrite and strictly only upload .jpg and .png file only
thanks for the help and advice you may give I really appreciate.
<?php
require("connection.php");
if(@$_POST ['submit'])
{
$file = $_FILES ['file'];
$name1 = $file ['name'];
$type = $file ['type'];
$size = $file ['size'];
$tmppath = $file ['tmp_name'];
if($name1!="")
{
if(move_uploaded_file ($tmppath, 'users/'.$name1))
{
$query="INSERT INTO profiles set photo='$name1'";
mysql_query ($query) or die ('could not updated:'.mysql_error());
echo "Profile picture updated";
}
}
}
?>
<?php
require("connection.php");
if(@$_POST ['submit'])
{
$file = $_FILES ['file'];
$type = $file ['type'];
$name1 = $user_id.$type;
$size = $file ['size'];
$tmppath = $file ['tmp_name'];
if($type != 'jpg' || $type != 'png') {
echo "File type must be JPG or PNG."
}else{
if($name1!="") {
if(move_uploaded_file ($tmppath, 'users/'.$name1))
{
$query="INSERT INTO profiles set photo='$name1'";
mysql_query ($query) or die ('could not updated:'.mysql_error());
echo "Profile picture updated";
}
}
}//must be jpg or png
}
}
?>