Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 未上载图像的输入_Php_File Upload - Fatal编程技术网

Php 未上载图像的输入

Php 未上载图像的输入,php,file-upload,Php,File Upload,嗯,我有一个页面来添加项目,并有一个上传文件到网站的输入。 该图像未上载到网站。。 问题在哪里? 代码介于以下两种类型之间: ## IMAGE IMAGE IMAGE IMAGE IMAGE ## add.php <form action="add.php" method="post"> <input name="title_name" type="text" class="form-control"

嗯,我有一个页面来添加项目,并有一个上传文件到网站的输入。 该图像未上载到网站。。 问题在哪里? 代码介于以下两种类型之间:

##      IMAGE       IMAGE       IMAGE       IMAGE       IMAGE       ##
add.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       ##





הוסף פריט
更改表单标签

<form action="add.php" method="post">

to

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


不会改变任何事情
if ($userfile > 0) {
if (!empty($_FILES["uploadedfile"])) {