输入图像未上传


Input for Image not uploading

嗯,我有一个页面来添加项目,并有一个输入用于上传文件到网站。图片没有上传到网站..问题在哪里?代码在:

之间
##      IMAGE       IMAGE       IMAGE       IMAGE       IMAGE       ##

. php

 <form action="add.php" method="post">
  <input name="title_name" type="text" class="form-control" style="width: 250px;margin-left:auto;margin-right:auto;display:inline;" placeholder="שם הפריט או נושא" /> <br />
  <textarea name="description" class="form-control" rows="5" placeholder="תיאור הפריט..." style="width: 250px;margin-left:auto;margin-right:auto;display:inline;"></textarea> <br />
  <input class="btn btn-primary" name="uploadedfile" type="file" style="width: 250px;margin-left:auto;margin-right:auto;display:inline;">   <br />
  <input name="type" type="text" class="form-control" style="width: 250px;margin-left:auto;margin-right:auto;display:inline;" placeholder="סוג הפריט" /> <br />
  <button type="submit" class="btn btn-primary" name="submitAdd">הוסף פריט</button>
  </form>
  <br>
  <div class="container">
  <?php 
  $title_name = $_POST['title_name'];
  $description = nl2br($_POST['description']);
  $username = $_SERVER['REMOTE_ADDR'];
  $type = $_POST['type'];
  $ok = 1;
  if(isset($_POST['submitAdd'])) {
  if(empty($title_name)) {
  echo '<div class="alert alert-danger fade in">
    <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
    <strong>שגיאה:</strong> The name of item can stay empty
  </div>';
  $ok = 0;
  }
  if(!empty($title_name) && !preg_match("/[A-Za-z0-9א-ת'.','_'- ]/", $title_name)) {
  echo '<div class="alert alert-danger fade in">
    <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
    <strong>שגיאה:</strong> שם הפריט מכיל תווים לא מורשים
  </div>';
  $ok = 0;
  }
  if(!empty($description) && !preg_match("/[A-Za-z0-9א-ת'.','_'- ]/", $description)) {
  echo '<div class="alert alert-danger fade in">
    <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
    <strong>שגיאה:</strong> תיאור הפריט מכיל תווים לא מורשים
  </div>';
  $ok = 0;
  }
if (!empty($userfile) && !preg_match('/^(?:[a-z0-9_-]|'.(?!'.))+$/iD', $userfile)) {
    echo '<div class="alert alert-danger fade in">
    <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
    <strong>שגיאה:</strong> Error with name of file
  </div>';
  $ok = 0;
}
    ##      IMAGE       IMAGE       IMAGE       IMAGE       IMAGE       ##
//
    $uploadImageStatus = 1;
    $userfile = $_POST['uploadedfile'];
    $name = strtolower($_FILES['uploadedfile']['name']);
    $ext = pathinfo($name, PATHINFO_EXTENSION);
    $allow = array("png", "jpeg", "jpg");
    $target_path = 0;
    if ($userfile > 0) {
    if(!in_array($ext, $allow)) {
        echo '<div class="alert alert-danger fade in">
        <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
        <strong>שגיאה:</strong> This file type dont allowed
        </div>';
        $uploadImageStatus = 0;
        }
        if($uploadImageStatus !== 0 && $_FILES['uploadedfile']['error'] !== 0) {
        $nameFile = $_FILES['uploadedfile']['name'];
        $target_path = "images/".basename(md5($_FILES['uploadedfile']['name']).time()).".$ext";
            if(move_uploaded_file($nameFile, $target_path)) { 
                $uploadImageStatus2 = 1; 
            }
        else {
            $uploadImageStatus2 = 0;
            echo '<div class="alert alert-danger fade in">
            <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
            <strong>שגיאה:</strong> Error on try upload this image
            </div>';
        }
    }
}
##      IMAGE       IMAGE       IMAGE       IMAGE       IMAGE       ##

change your form tag

<form action="add.php" method="post">
to
<form action="add.php" method="post" enctype="multipart/form-data">

,也改变

if ($userfile > 0) {

if (!empty($_FILES["uploadedfile"])) {