简体   繁体   English

重命名个人资料图片上传并插入数据库

[英]rename profile picture on upload and insert into database

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 有人可以帮助我实现我的上传脚本吗,下面的代码能够将图像上传到数据库中,因此我想将要上传的图像更改/重命名为正在将其作为个人资料图片上传的用户ID,以避免文件被覆盖并且严格只上传.jpg和.png文件
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
      }
}
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM