Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/294.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_Jquery_Html_Css - Fatal编程技术网

上载产品php脚本不工作

上载产品php脚本不工作,php,jquery,html,css,Php,Jquery,Html,Css,我创建了一个Php脚本来将产品上传到我的网站,但它不起作用,也没有显示任何错误。我被这个问题困扰了5天多,我仍然在寻找错误,但我不能请任何人检查我的代码,我需要立即帮助 <?php require_once $_SERVER['DOCUMENT_ROOT'].'/tutorial/core/init.php'; if(!is_logged_in()){ login_error_redirect(); } include 'includes/head.php'; includ

我创建了一个
Php
脚本来将产品上传到我的网站,但它不起作用,也没有显示任何错误。我被这个问题困扰了5天多,我仍然在寻找错误,但我不能请任何人检查我的代码,我需要立即帮助

    <?php
 require_once $_SERVER['DOCUMENT_ROOT'].'/tutorial/core/init.php';
 if(!is_logged_in()){
  login_error_redirect();
}
include 'includes/head.php';
include 'includes/navigation.php';
if (isset($_GET['add'])) {
    $brandQuery = $db->query("SELECT * FROM brand ORDER BY brand");
    $parentQuery = $db->query("SELECT * FROM categories WHERE parent = 0 ORDER BY category");
  if ($_POST) {
    $title = sanitize($_POST['title']);
    $brand = sanitize($_POST['brand']);
    $categories = sanitize($_POST['child']);
    $price = sanitize($_POST['price']);
    $list_price = sanitize($_POST['list_price']);
    $sizes = sanitize($_POST['sizes']);
    $description = sanitize($_POST['description']);
    $dbpath = '';
    $errors= array();
    if(!empty($_POST['sizes'])) {
      $sizeString = sanitize($_POST['sizes']);
      $sizeString = rtrim($sizeString,',');
      $sizesArray = explode(',',$sizeString);
      $sArray = array();
      $qArray = array();
      foreach($sizesArray as $ss){
        $s = explode(':', $ss);
        $sArray[] = $s[0];
        $qArray[] = $s[1];
      }
    }else{$sizesArray = array();}
     $required = array('title','brand','price','parent','child','sizes');
     foreach($required as $field){
      if($_POST[$field] == ''){
        $errors[] = 'All Field With and Astrisk are required.';
        break;
      }
     }
     if (!empty($_FILES)) {
       var_dump($_FILES);
       $photo = $_FILES['photo'];
       $name = $photo['name'];
       $nameArray = explode('.',$name);
       $fileName = $nameArray[0];
       $fileExt = $nameArray[1];
       $mime = explode('/',$photo['type']);
       $mimeType = $mime[0];
       $mimeExt = $mime['1'];
       $tmpLoc = $photo['tmp_name'];
       $fileSize = $photo['size'];
       $allowed = array('png','jpg','jpeg','gif');
       $uploadName = md5(microtime()).'.'.$fileExt;
       $uploadPath = BASEURL.'images/proimg/'.$uploadName;
       $dbpath = '/tutorial/images/proimg/'.$uploadName;
       if ($mimeType != 'image') {
         $errors[] = 'The file must be an image.';
       }
       if (!in_array($fileExt, $allowed)) {
         $errors[] = 'The file extension must be a png, jpg, or gif';
       }
       if ($fileSize > 15000000) {
         $errors[] = 'The file size must be under 15MB.';
       }
       if($fileExt != $mimeExt && ($mimeExt == 'jpeg' && $fileExt != 'jpg')){
        $errors[] = 'File extension does not match the file.';
       }
     }
     if(!empty($errors)){
      echo display_errors($errors);
     }else{
      //upload file and insert into database
      move_uploaded_file($tmpLoc,$uploadPath);
      $insertSql = "INSERT INTO products ('title','price','list_price','brand','categories','image','sizes','description') VALUES 
      ('$title','$price','$list_price','$brand','$categories','$sizes','$dbpath','$description')";
      $db->query($insertSql);
      header('Location: products.php');

     }
  }
?>
    <h2 class="text-center">Add A New Product</h2><hr>
    <form action="products.php?add=1" method="POST" enctype="multipart/form-data">
        <div class="form-group col-md-3">
            <label for="title">Title*:</label>
            <input type="text" name="title" class="form-control" id="title" value="<?=((isset($_POST['title']))?sanitize($_POST['title']):''); ?>">
        </div>
        <div class="form-group col-md-3">
            <label for="brand">Brand*:</label>
            <select class="form-control" id="brand" name="brand">
              <option value=""<?= ((isset($_POST['brand']) && $_POST['brand'] == '')?' selected':''); ?>></option>
              <?php while($brand = mysqli_fetch_assoc($brandQuery)): ?>
                <option value="<?=$brand['id'];?>"<?=((isset($_POST['brand']) && $_POST['brand'] == $brand['id'])?' selected':''); ?>><?=$brand['brand'];?></option>

              <?php endwhile; ?>    
            </select>
        </div>
        <div class="form-group col-md-3">
            <label for="parent">Parent Category*:</label>
            <select class="form-control" id="parent" name="parent">
               <option value=""<?=((isset($_POST['parent']) && $_POST['parent'] == '')?' selected':''); ?>></option>
               <?php while($parent = mysqli_fetch_assoc($parentQuery)): ?>
                 <option value="<?=$parent['id'];?>"<?= ((isset($_POST['parent']) && $_POST['parent'] == $parent['id'])?' select':'') ?>><?=$parent['category'];?></option>
               <?php endwhile; ?>
            </select>
        </div>
        <div class="form-group col-md-3">
            <label for="child">Child Category*:</label>
            <select id="child" name="child" class="form-control">

            </select>
        </div>
        <div class="form-group col-md-3">
            <label for="price">Price*:</label>
            <input type="text" id="price" name="price" class="form-control" value="<?=((isset($_POST['price']))?sanitize($_POST['price']):'');?>">
        </div>
        <div class="form-group col-md-3">
            <label for="price">list-Price*:</label>
            <input type="text" id="list_price" name="list_price" class="form-control" value="<?=((isset($_POST['list_price']))?sanitize($_POST['list_price']):'');?>">
        </div>

        <div class="from-group col-md-3">
            <label>Quantity & more</label>
            <button class="btn btn-default form-control" onclick="jQuery('#sizesModal').modal('toggle');return false;">Quantity</button>
        </div>
      <div class="from-group col-md-3">
        <label>Quantity Preview</label>
        <input type="text" class="form-control" name="sizes" id="sizes" value="<?=((isset($_POST['sizes']))?$_POST['sizes']:'');?>" readonly>
      </div>
        <div class="form-group col-md-6">
            <label for="photo">Product Photo:</label>
            <input type="file" name="photo" id="photo" class="form-control">
        </div>
        <div class="form-group col-md-6">
            <label for="description">Description:</label>
            <textarea id="description" name="description" class="form-control" rows="6"><?= ((isset($_POST['description']))?sanitize($_POST['description']):'');?></textarea>
        </div>
        <div class="form-group">
        <input type="submit" value="Add Product" class="form-control btn btn-success">
        </div><div class="clearfix"></div>

    </form>
    <!-- Modal -->
    <div class="modal fade" id="sizesModal" tabindex="-1" role="dialog" aria-labelledby="sizesModalLabel">
  <div class="modal-dialog modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="sizesModalLabel">Quantity & about</h4>
      </div>
      <div class="modal-body">
       <div class="container-fluid">
         <?php for ($i=1; $i <= 1;$i++): ?> 
          <div class="form-group col-md-4">
             <label for="size<?=$i; ?>">More info:</label>
             <input type="text" name="size <?=$i; ?>" id="size<?=$i; ?>" value="<?=((!empty($sArray[$i-1]))?$sArray[$i-1]:''); ?>" class="form-control">
           </div> 
             <div class="form-group col-md-2">
             <label for="qty<?=$i; ?>">Quantity:</label>
             <input type="number" name="qty<?=$i; ?>" id="qty<?=$i; ?>" value="<?=((!empty($qArray[$i-1]))?$qArray[$i-1]:''); ?>" min="0" class="form-control">
           </div>
         <?php endfor; ?>
         </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary" onclick="updateSizes();jQuery('#sizesModal').modal('toggle');return false;">Save changes</button>
      </div>
    </div>
  </div>
</div>

<?php  } else {

$sql = "SELECT * FROM products WHERE deleted = 0";
$presults = $db->query($sql);
if (isset($_GET['featured'])) {
    $id = (int)$_GET['id'];
    $featured = (int)$_GET['featured'];
    $featuredSql = "UPDATE products SET featured = '$featured' WHERE id = '$id'";
    $db->query($featuredSql);
    header('Location: products.php');
}
?>
<h2 class="text-center">Upload Products</h2>
<a href="products.php?add=1" class="btn btn-success pull-right" id="add-product-btn" style="margin-right: 100px;">Add Product</a><div class="clearfix"></div>
<hr>
<table class="table table-bordered table-condensed table-striped">
<thread>
<th></th> <th>Product</th> <th>Price</th> <th>Category</th> <th>Feature</th> <th>Sold</th>
</thread>
<tbody>
    <?php while($product = mysqli_fetch_assoc($presults)):
          $childID = $product['categories'];
          $catSql = "SELECT * FROM categories WHERE id = '$childID'";
          $result = $db->query($catSql);
          $child = mysqli_fetch_assoc($result);
          $parentID = $child['parent'];
          $pSql = "SELECT * FROM categories WHERE id = '$parentID'";
          $presult = $db->query($pSql);
          $parent = mysqli_fetch_assoc($presult);
          $category = $parent['category']. '~'.$child['category'];
     ?>
        <tr>
            <td>
                <a href="products.php?edit=<?=$product['id'];?>" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-pencil"></span></a>
                <a href="products.php?delete=<?=$product['id'];?>" class="btn btn-xs btn-default"><span class="glyphicon glyphicon-remove"></span></a>

            </td>
            <td><?=$product['title']; ?></td>
            <td><?=money($product['price']); ?></td>
            <td><?= $category; ?></td>
            <td><a href="products.php?featured=<?=(($product['featured'] == 0)?'1':'0');?>&id=<?=$product['id']; ?>" class="btn btn-xs btn-default">
            <span class="glyphicon glyphicon-<?=(($product['featured']==1)?'minus':'plus');?>"></span>
            </a>&nbsp <?=(($product['featured'] == 1)?'Featured Product':'');?></td>
            <td>0</td>
        </tr>

    <?php endwhile; ?>
</tbody>
</table>

<?php } include 'includes/footer.php'; ?>

您可以检查几件事情来确保这一点。因为这是一个文件资源,所以您也必须考虑代码之外的内容。我知道在过去的5天里,您已经做了大量的研发工作,可能已经完成了下面提到的所有步骤,但请再试一次。我希望它能解决你的问题

  • 您上载的位置是否具有适当的写入权限
  • 使错误报告在代码顶部可用
  • 无论在何处使用move\u上传的\u文件,都要创建错误日志
  • 使用断点检查您的代码是否到达代码的上载点

  • 正如在您的问题评论中所说的,检查move_上传的文件函数返回的内容
  • php\上传值\最大\文件大小=16G

    php_值post_max_size=16G

    php_值最大输入时间3600

    php_值最大执行时间3600


  • 在.htaccess中输入此代码,并根据需要更改值。

    检查move_upload_file函数返回的值(真/假)。其中@Param Bhat//上载文件并插入数据库move_upload_file($tmpLoc,$uploadPath);=>如果文件正在上载或未上载,请选中此行。添加if(move_uplated_file($tmpLoc,$uploadPath)){echo“true”;}否则{echo“false”;}您正在使用此函数move_uplated_file,因此将其放入如下变量$abc=move_uplated_file(src,dest);然后打印这张$abc来检查它返回的内容。它不工作了。