PHP文件上传不起作用

PHP文件上传不起作用,php,file-upload,Php,File Upload,我在Ubuntu上。我试图采取用户文件上传的小图片。我检查了$u文件,里面有数据。我试图调试move命令,但它没有响应任何内容 if ($_SERVER['REQUEST_METHOD'] == 'POST' ){ //Now handle everything if(isset($_POST["submit"])) { print_r($_FILES); //Store the image if(!empty($_FILES['u

我在Ubuntu上。我试图采取用户文件上传的小图片。我检查了$u文件,里面有数据。我试图调试move命令,但它没有响应任何内容

if ($_SERVER['REQUEST_METHOD'] == 'POST' ){
    //Now handle everything
    if(isset($_POST["submit"])) {
        print_r($_FILES);
        //Store the image
        if(!empty($_FILES['uploaded_file']))
        {
          $path = "/neel/public/img/";
          $path = $path.basename($_FILES['uploaded_file']['name']);
          if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $path)) {

            echo 'Its working';
          } else{
              echo 'I am done!!!';
              die();
          }
        } 
    createnewEvent($conn);
    header('Location:/neel/index.php');
    }
}

您可以通过检查文件名来检查文件是否存在

if(!empty($_FILES['file']['name'])) 

其中,
file
是文件输入字段的名称。

如果$\u服务器['REQUEST\u METHOD']不是“POST”,您显示的脚本将只“不回显任何内容”。假设您对事件的描述是准确的,那么问题在于@halojoy要求您在此处显示的形式


我希望您不要将脚本重定向回自身。此外,您不应该尝试在回音后进行重定向。

p.G在这里是正确的。
如果$\u POST['submit']
您应该选中此项:

if(isset($\u FILES['uploaded\u file']['name'])
试试这段代码,这是一个完整的PHP注册表单,Bootstrap

HTML



创建新帐户

你能给我们看一下吗,所以你要展示的是/neel/admin.php。你得到任何输出了吗?那没有帮助吗1)那只是表单的一部分。2) 您向我们展示的代码不会以您描述的方式运行(除非它在内核转储中崩溃)。如果你不能描述这个问题,我们也帮不了你。
<div class="container">
    <div class="row">
        <br>
            <h1 class="text-center">Create new account</h1>
            <br>
        <div class="col-lg-4 col-md-6 col-sm-12">
            <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" enctype="multipart/form-data">
                <div class="form-group">
                    <input type="text" class="form-control form-control-lg" name="name" placeholder="Your Name">
                </div>
                <div class="form-group">
                    <input type="text" class="form-control form-control-lg" name="username" placeholder="Username">
                </div>
                <div class="form-group">
                    <input type="password" class="form-control form-control-lg" name="password" placeholder="Password">
                </div>
                <div class="form-group text-center">
                    <div class='file-input'>
                        <input type='file' name="profile-img">
                        <span class='button label' data-js-label>Choose your profile image</span>
                    </div>
                </div>
                <div class="form-group">
                    <input type="submit" class="btn btn-success form-control form-control-lg" name="signup" value="Signup">
                </div>
            </form>
        </div>
    </div>
</div>
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $errors;
    if (empty($_POST['name'])) {
        $errors[] = "Name field is empty";
    }
    if (empty($_POST['username'])) {
        $errors[] = "Username field is empty";
    }
    if (empty($_POST['password'])) {
        $errors[] = "Password field is empty";
    }
    if (empty($_FILES['profile-img'])) {
        $errors[] = "You should upload profile image";
    } else{
        $img = $_FILES['profile-img'];
        $ext = end(explode('.', $img['name']));
        $allowed_extensions = array('jpg', 'jpeg', 'png', 'gif');
        $max_size = 4; //MegaBytes
        if (! in_array($ext, $allowed_extensions)) {
            $errors[] = "Please , Choose a valid image";
        }
        $img_size = $img['size'] / 1000000; // By Megabyte
        if ($img_size > $max_size) {
            $errors[] = "This picture is so large";
        }
    }
    if (!empty($errors)) {
        echo '<div class="container">';
        foreach ($errors as $error) {
            echo '
                <div class="alert alert-danger" role="alert">
                ' . $error . '
                </div>
            ';
        }
        echo "</div>";
    } else {
        $username = filter_var(htmlentities(trim($_POST['username'])), FILTER_SANITIZE_STRING);
        $name = filter_var(htmlentities(trim($_POST['name'])), FILTER_SANITIZE_STRING);
        $password = sha1(filter_var(htmlentities(trim($_POST['password'])), FILTER_SANITIZE_STRING));
        // Profile Picture :-
        $imgname = uniqid(uniqid()) . @date("Y-m-d") . "." . $ext;

        $target_bath = "uploads/imgs/";
        $target_bath = $target_bath . basename($imgname);
        $orginal_img = $img['tmp_name'];

        if (move_uploaded_file($orginal_img, $target_bath)) {
            $sql = "INSERT INTO users(name, username, password,profile_picture, r_d) VALUES ('$name', '$username', '$password', '$target_bath', NOW())";
            $result = mysqli_query($conn, $sql);
            header('location: ./login.php');
        }


    }
}