2017-12-24 9 views
-1

저는 우분투입니다. 작은 이미지를 업로드하는 사용자 파일을 가져 오려고합니다. $ _FILES가 데이터로 가득 차 있는지 확인했습니다. 내가 이동 명령을 디버깅하려고했지만 아무것도 에코 doesnot.PHP FileUpload가 작동하지 않습니다.

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'); 
    } 
} 
+1

당신은 U를 보여줄 수 ■ <양식 페이지? – halojoy

+0

+0

그래서 당신이 보여주는 것은 /neel/admin.php입니다. 출력물을 얻었습니까? – halojoy

답변

1

파일 이름이 존재하는지 확인할 수 있습니다. file 파일에 대한 입력 필드의 이름입니다

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

.

+0

그게 도움이되지 않았다 –

0

$ _SERVER [ 'REQUEST_METHOD']이 (가) "POST"가 아닌 경우 표시된 스크립트는 "아무 것도 울리지 않습니다". 이벤트에 대한 설명이 정확하다고 가정하면 문제는 @halojoy가 여기에 표시하도록 요청한 형식입니다.

스크립트를 다시 리디렉션하지 않기를 바랍니다. 또한 에코 후 리디렉션을 시도해서는 안됩니다.

+0

+0

1) 이는 양식의 일부일뿐입니다. 2) 우리가 보여준 코드는 (코어 덤프와 충돌하지 않는 한) 당신이 설명하는 방식으로 행동하지 않을 것입니다. 문제를 설명 할 수 없다면 도움을 줄 수 없습니다. – symcbean

0

위의 G는 정확합니다.
당신이 확인해야하는 대신 검사의
, $ _POST 경우 [ '제출']는 PHP와 완전한 가입 폼의 코드를 시도
if(isset($_FILES['uploaded_file']['name']))

0

를, 부트 스트랩

HTML

<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> 

PHP

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'); 
     } 


    } 
}