简体   繁体   中英

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 -

html to send the files:

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

  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'); is not working.

Just to check, I commented/removed the 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

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. The file sizes are anyway less than 1MB, so this is not at all an issue, I guess.

The isset() function can only return either TRUE or FALSE but you are checking to see if it has the value of POST. By just having isset($_POST['submit']) in the if statement, you are checking to see if it is set to TRUE. To check if it is false, you would change it to !isset($_POST['submit']) .

The error log will be more precise as to the cause of the 500 error message. I don't think the error in the if statement would have caused a 500 error .

If you can't check error logs then, at the top of your PHP file add

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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