Php $\u发布未在上载表单上工作

Php $\u发布未在上载表单上工作,php,html,forms,post,upload,Php,Html,Forms,Post,Upload,我有这个上传表格: <form action="upload.php" enctype="multipart/form-data" method="post"> <b>Select your image:</b><br><input type="file" name="userfile" id="file" size="90%" /><br> (Max size

我有这个上传表格:

        <form action="upload.php" enctype="multipart/form-data" method="post">
            <b>Select your image:</b><br><input type="file" name="userfile" id="file" size="90%" /><br>
            (Max size: 10mb)<br>
            <b>Browseable:</b><br><input type="radio" name="browse" id="browse" value="1" /> Yes <input type="radio" name="browse" id="browse" value="0" /> No<br>
            <input type="submit" value="Upload Image" size="100" />
        </form>

选择您的图像:

(最大大小:10mb)
可浏览:
是否
下面是PHP代码:

    <?PHP
    $maxsize = 10485760; // Max File Size IN BYtes
    $accepted = array('png', 'jpg', 'jpeg','JPEG', 'gif', 'ico', 'tif', 'bmp', 'PNG');
    $length = 10;
    $randomString = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, $length);

    if($_SERVER['REQUEST_METHOD'] == 'POST') {

        preg_match('/\.([a-zA-Z]+?)$/', $_FILES['userfile']['name'], $matches);

        if(in_array(strtolower($matches[1]), $accepted)) {

            if($_FILES['userfile']['size'] <= $maxsize) {

                $newname = md5_file($_FILES['userfile']['tmp_name']).'.'.$matches[1];

                $browse = $_POST["browse"];

                if ($browse = "1") {
                $filedir = 'img';
                } else {
                $filedir = 'noimg';
                }

                move_uploaded_file($_FILES['userfile']['tmp_name'], $filedir.'/'.$newname);

                header("Location: index.php?p=uploaded&img=$newname");
            } else 
                header("Location: index.php?p=error&num=2");
        } else
        header("Location: index.php?p=error&num=1");
    }
    ?>  


$\u POST[“浏览”]之后的部分不起作用。此脚本的目的是在上载后将图像放在公用或专用文件夹中。我也很好奇这个上传脚本是否安全。

您有assignemt操作符(
=
),而不是比较(
=
=


我通过
假设$\u POST[“browse”]之后的部分不起作用。
意味着真正的块总是被触发?如果是,则将
If($browse=“1”)
更改为
If($browse==“1”)
。您的
if
语句正在检查
$browse
是否可以赋值为1,而不是它是否等于1

if ($browse = "1") {
您正在将1分配给$browse…>>"==" !

然后做:

$res = move_uploaded_file($_FILES['userfile']['tmp_name'], $filedir.'/'.$newname);
var_dump($res);
die;

要查看发生了什么:)

=“MB”,而不是“MB”。试着打印$browse,看看你得到了什么。这是我的问题,我忽略了这一点。我在想还有更大的问题。
$res = move_uploaded_file($_FILES['userfile']['tmp_name'], $filedir.'/'.$newname);
var_dump($res);
die;