0

有人可以帮我实现我的上传脚本吗,使用以下代码可以将图像上传到数据库中,因此我想更改/重命名正在上传的图像到将图像上传为个人资料图片的用户 ID,以避免文件覆盖严格只上传 .jpg 和 .png 文件,
感谢您提供的帮助和建议,我非常感谢。

<?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";
}
}
}
?>
4

1 回答 1

0
<?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
      }
}
?>
于 2013-05-15T10:12:57.643 回答