处理标记时出错<;输入类型=';文件'/&燃气轮机;使用PHP

处理标记时出错<;输入类型=';文件'/&燃气轮机;使用PHP,php,html,Php,Html,对于我的网站,我希望用户发送一张图片。我当前的php代码无法检查内容 我试图在html代码中直接限制扩展 if(isset($\u POST['postphoto'])){ if(设置($_文件['picture'])和!空($_文件['picture']['name'])){ $comentaryssender=htmlspecialchars($_POST['commentaryssenderpost']); $extensionsValides=数组('jpg','jpeg','gif',

对于我的网站,我希望用户发送一张图片。我当前的
php
代码无法检查内容

我试图在
html
代码中直接限制扩展

if(isset($\u POST['postphoto'])){
if(设置($_文件['picture'])和!空($_文件['picture']['name'])){
$comentaryssender=htmlspecialchars($_POST['commentaryssenderpost']);
$extensionsValides=数组('jpg','jpeg','gif','png');
$extensionUpload=strtolower(substr(strrchr($_FILES['picture']['name'],'.')),1));
$chemin=“picture/post/”$id.“..$extensionUpload;
移动上传的文件($文件['picture']['tmp\U name'],$chemin);
}否则{
$message=“请输入图片!”;
}
}
当我发送带有图像的表单时,它返回错误消息:

请输入图片


您可以这样做:

    $uploadStatus = 1;
    $uploadedFile = '';
    if (!empty($_FILES["img1"]["name"]))
    {
        $fileName = basename($_FILES["img1"]["name"]);
        $filenamewithoutextension = strtolower(pathinfo($fileName, PATHINFO_FILENAME));
        $fileType = strtolower(pathinfo($fileName, PATHINFO_EXTENSION));

        $filename_to_store = $filenamewithoutextension. '_' .uniqid(). '.' .$fileType;

        $allowTypes = array(
            'jpg',
            'png',
            'jpeg'
        );
        if (in_array($fileType, $allowTypes))
        {
            if (move_uploaded_file($_FILES["img1"]["tmp_name"], $uploadDir.$filename_to_store))
            {
                $uploadedFile = $filename_to_store;
            }
            else
            {
                $uploadStatus = 0;
                $response['message'] = 'Sorry, there was an error uploading your file.';
            }
        }
        else
        {
            $uploadStatus = 0;
            $response['message'] = 'Sorry, only JPG, JPEG & PNG files are allowed.';
        }
    }
    if($uploadStatus==1)
    { //execute sth else if you wish, like printing success message }
PS:我想您的html代码是正确的,否则这将无法工作