简体   繁体   English

在move_uploaded_files()中出现500错误

[英]500 error in move_uploaded_files()

I am not sure what the error is and I am unable to read the error since I am being redirected to 500 error and not able to judge the error, here is my code - 我不确定错误是什么,并且由于我被重定向到500错误并且无法判断错误,因此无法读取错误,这是我的代码-

html to send the files: html发送文件:

  <form action="#" method="POST" class='form-horizontal form-validate' id="add-image" enctype='multipart/form-data'>
    <div class="control-group">
      <label for="select" class="control-label">Product</label>
      <div class="controls">
        <input type="hidden" name="type" id="type" class="input-xlarge" value="image">
        <input type='hidden' name="issubmit" value="1">
        <select name="product" id="product" class='input-xxlarge'>
<?php
  $testsql = "SELECT product_id,UPPER(concat(product_code,' - ',product_name,' - ',category_name,' - ', subcat_name)) as product_name FROM category ca,product pro,subcategory su where su.subcat_id=pro.subcat_id and su.category_id=ca.category_id ORDER BY product_id ";
  $testresult = mysql_query($testsql);
  while ($row = mysql_fetch_array($testresult))
  {
    echo "<option value=\"". $row['product_id']."\">". $row['product_name']. "</option>";
  }
?>
        </select>
      </div>
    </div>
    <div class="control-group">
      <label for="textfield" class="control-label"></label>
      <div class="controls">
        <div class="check-demo-col" style="width:175px;">
          <div class="fileupload fileupload-new" data-provides="fileupload">
            <div class="fileupload-new thumbnail" style="width: 100px; height: 100px;"><img src="../upload/sample.jpg" /></div>
            <div class="fileupload-preview fileupload-exists thumbnail" style="max-width: 100px; max-height: 100px; line-height: 2px;"></div>
            <div>
              <span class="btn btn-file"><span class="fileupload-new">Select main-view</span><span class="fileupload-exists">Change</span><input type="file" name='imagefile[]' /></span>
              <a href="#" class="btn fileupload-exists" data-dismiss="fileupload">Remove</a>
            </div>
          </div>
        </div>
        <div class="check-demo-col" style="width:175px;">
          <div class="fileupload fileupload-new" data-provides="fileupload">
            <div class="fileupload-new thumbnail" style="width: 100px; height: 100px;"><img src="../upload/sample.jpg" /></div>
            <div class="fileupload-preview fileupload-exists thumbnail" style="max-width: 100px; max-height: 100px; line-height: 20px;"></div>
            <div>
              <span class="btn btn-file"><span class="fileupload-new">Select left-view</span><span class="fileupload-exists">Change</span><input type="file" name='imagefile[]' /></span>
              <a href="#" class="btn fileupload-exists" data-dismiss="fileupload">Remove</a>
            </div>
          </div>
        </div>
        <div class="check-demo-col" style="width:175px;">
          <div class="fileupload fileupload-new" data-provides="fileupload">
            <div class="fileupload-new thumbnail" style="width: 100px; height: 100px;"><img src="../upload/sample.jpg" /></div>
            <div class="fileupload-preview fileupload-exists thumbnail" style="max-width: 100px; max-height: 100px; line-height: 20px;"></div>
            <div>
              <span class="btn btn-file"><span class="fileupload-new">Select right-view</span><span class="fileupload-exists">Change</span><input type="file" name='imagefile[]' /></span>
              <a href="#" class="btn fileupload-exists" data-dismiss="fileupload">Remove</a>
            </div>
          </div>
        </div>
        <div class="check-demo-col" style="width:175px;">
          <div class="fileupload fileupload-new" data-provides="fileupload">
            <div class="fileupload-new thumbnail" style="width: 100px; height: 100px;"><img src="../upload/sample.jpg" /></div>
            <div class="fileupload-preview fileupload-exists thumbnail" style="max-width: 100px; max-height: 100px; line-height: 20px;"></div>
            <div>
              <span class="btn btn-file"><span class="fileupload-new">Select top-view</span><span class="fileupload-exists">Change</span><input type="file" name='imagefile[]' /></span>
              <a href="#" class="btn fileupload-exists" data-dismiss="fileupload">Remove</a>
            </div>
          </div>
        </div>
        <div class="check-demo-col" style="width:175px;">
          <div class="fileupload fileupload-new" data-provides="fileupload">
            <div class="fileupload-new thumbnail" style="width: 100px; height: 100px;"><img src="../upload/sample.jpg" /></div>
            <div class="fileupload-preview fileupload-exists thumbnail" style="max-width: 100px; max-height: 100px; line-height: 20px;"></div>
            <div>
              <span class="btn btn-file"><span class="fileupload-new">Select bottom-view</span><span class="fileupload-exists">Change</span><input type="file" name='imagefile[]' /></span>
              <a href="#" class="btn fileupload-exists" data-dismiss="fileupload">Remove</a>
            </div>
          </div>
        </div>        
      </div>
    </div>
    <div class="control-group">
      <label for="select" class="control-label">Status</label>
      <div class="controls">
        <select name="status" id="status" class='input-large'>
          <option value="active">Active</option>
          <option value="disabled">Disabled</option>
          <option value="inactive">Inactive</option>
        </select>
      </div>
    </div>
    <div class="form-actions">
      <input type="submit" class="btn btn-primary" value="Submit" name="submit">
      <button type="button" class="btn">Cancel</button>
    </div>
  </form>

and my php is: 和我的PHP是:

  if(isset($_REQUEST['submit']))
  { 

    if(isset($_REQUEST['product']))
    {
      $product=$_REQUEST['product'];
      // echo $product;        
    }
    if(isset($_REQUEST['status']))
    {
      $status=$_REQUEST['status'];
      // echo $status;        
    }

    $target = "../upload/"; 
    $count=0;
    foreach ($_FILES['imagefile']['name'] as $filename) 
    {
      $temp=$target;
      $tmp=$_FILES['imagefile']['tmp_name'][$count];

      $extension = pathinfo($filename, PATHINFO_EXTENSION);
      // echo $extension;
      $temp=$temp.basename($product.'_'.($count + 1).'.'.$extension);
      move_uploaded_file($tmp,$temp);
      // echo $temp;

      //This gets all the other information from the form 
      $image=($_FILES['imagefile']['name']); 
      if($image[$count])
      {
        // $insert=mysql_query("INSERT INTO image VALUES (DEFAULT,'$product','$temp','$image[$count]','$status')") ;
      }
      $count=$count + 1;
      $temp='';
      $tmp='';
    }
  }

I get the following error: 我收到以下错误:

The server encountered an internal error or misconfiguration and was unable to complete your request. 服务器遇到内部错误或配置错误,无法完成您的请求。 Please contact the server administrator to inform of the time the error occurred and of anything you might have done that may have caused the error. 请与服务器管理员联系,以通知错误发生的时间以及您可能做的任何可能导致错误的事情。 More information about this error may be available in the server error log. 服务器错误日志中可能会提供有关此错误的更多信息。

I'm not able to read the error log and error_reporting(E_ALL); ini_set('display_errors', 'on'); 我无法读取错误日志和error_reporting(E_ALL); ini_set('display_errors', 'on'); error_reporting(E_ALL); ini_set('display_errors', 'on'); is not working. 不管用。

Just to check, I commented/removed the move_uploaded_file($tmp,$temp); 只是为了检查,我评论/删除了move_uploaded_file($tmp,$temp); and found no error with the format or code. 并没有发现格式或代码错误。 It is the move_uploaded_files() that is giving the trouble and I have tried adding 麻烦的是move_uploaded_files() ,我尝试添加

php_value upload_max_filesize 8M
php_value post_max_size 8M
php_value max_execution_time 200
php_value max_input_time 200

to .htaccess and found no help. .htaccess ,没有任何帮助。 The file sizes are anyway less than 1MB, so this is not at all an issue, I guess. 无论如何,文件大小都小于1MB,所以我想这根本不是问题。

The isset() function can only return either TRUE or FALSE but you are checking to see if it has the value of POST. isset()函数只能返回TRUE或FALSE,但是您正在检查它是否具有POST的值。 By just having isset($_POST['submit']) in the if statement, you are checking to see if it is set to TRUE. 通过在if语句中仅包含isset($_POST['submit']) ,即可检查其是否设置为TRUE。 To check if it is false, you would change it to !isset($_POST['submit']) . 要检查它是否为假,可以将其更改为!isset($_POST['submit'])

The error log will be more precise as to the cause of the 500 error message. 错误日志将更准确地说明500错误消息的原因。 I don't think the error in the if statement would have caused a 500 error . 我认为if语句中的错误不会导致500错误

If you can't check error logs then, at the top of your PHP file add 如果您无法检查错误日志,则在PHP文件顶部添加

error_reporting(E_ALL);
ini_set('display_errors', 'on');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM