文件上传显示“不支持的文件”

时间:2017-03-31 20:14:32

标签: javascript php jquery html css

我需要帮助,此脚本在上传图片时显示“不支持的文件” 我无法弄清楚可能的错误。

我创建了一个运行文件上传的模态表单,当用户点击“标记为已付款”时,会在附加图像的位置出现模式表单。
点击提交,它会显示不支持的文件错误...

HTML

echo '<center class="fa-boardx">
        <div class="x fa-boardx"><div class="container">';
echo '<div id="heading-breadcrumbs" style="width:94%;">
        <div class="panel panel-primary">
          <div class="panel-heading">
            <h3 class="panel-title"><strong>AWAITING PAYMENT</h3>
          </div>
          <br>
          <h1>AMOUNT: <span><b> ₦ '.$emoney.'</b><span></h1>';

if($set['autopurge'] > 0){
  echo '<code>YOUR ACCOUNT WILL BLOCKED IN
    <h2>(<font color="red"> '.ceil(($mergto['xtime'] - time())/60 * 24).'</font>)<br/>';
  include '../count.php';
  echo '</code><br/>PAY BEFORE THIS TIME TO ENJOY DONATIONS</h2>';
}
 echo '<b class="green"><h4>Pay To Name: <span>'.htmlspecialchars($umprof['firstname']).' '.$umprof['lastname'].' </span><br/> <br>
  Phone Number: <span>'.htmlspecialchars($umprof['phone']).'</span><br/><br>

  Bank Name: <span>'.htmlspecialchars($umprof['bankname']).'</span><br/><br>

  Account Name: <span>'.htmlspecialchars($umprof['accname']).'</span><br/><br>
  Account Number: <span>'.htmlspecialchars($umprof['accno']).'</span></h4></b><br>';

if($mergto['status'] < 1){
  echo '<form action="uploader.php" method="POST" enctype="multipart/form-data" >
    <input type="hidden" name="sendi" value="'.$mergto['sender'].'"/>
    <input type="hidden" name="rendi" value="'.$mergto['reciever'].'"/>
    </div>
    </div>
    <button class="button button-xlarge button-rounded" data-toggle="modal" data-target=".modal-payment">MARK AS PAID
    </button>
    <!-- MODAL   -->
    <div class="modal fade modal-payment" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
      <div class="modal-dialog modal-lg">
        <div class="modal-body">
          <div class="modal-content">
            <div class="modal-header">
              <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
              <h4 class="modal-title" id="myModalLabel">I SEND THE MONEY</h4>
            </div>
            <div class="modal-body">

              <form action="uploader.php" method="POST" enctype="multipart/form-data">
                <input type="hidden" name="sender" value="'.htmlspecialchars($muprof['username']).'"/>
                <input type="hidden" name="iid" value="12112">
                <input type="hidden" name="paid" value="12112">
                <div class="row">
                  <div class="col-md-12">
                    <label>Payment Type:</label>
                    <input name="ptyp" class="form-control input-lg" type="text" required="">
                  </div>
                </div>
                <br>
                <div class="row">
                  <div class="col-md-12">
                    <label>Name On Pay Slip:</label>
                    <input name="mName" class="form-control input-lg" type="text" required="">
                  </div>
                </div>
                <br>

                <div class="row">
                  <div class="col-md-12 bottommargin">
                    <label>PAYMENT IMAGE:</label><br>
                    <input  type="file" id="input-8" name="mFile" class="file-loading"  accept="image/gif, image/jpeg"/>

                  </div>
                </div>

                <div class="row">
                  <div class="col-md-12">
                    <button type="submit" class="btn btn-lg btn-block btn-success"  id="sendmail"> SUBMIT </button>
                  </div>
                </div>

              </form>

            </div>
          </div>
        </div>
      </div>
    </div>';

Uploader.php
uploader.php是单独放置的

<?php
include ('../inc/config.php');
$UploadDirectory  = 'uploads/'; //Upload Directory, ends with slash & make sure folder exist
$SuccessRedirect  = 'main.php'; //Redirect to a URL after success

if (!@file_exists($UploadDirectory)) {
  //destination folder does not exist
  die("Make sure Upload directory exist!");
}

if($_POST)
{
    if(!isset($_POST['mName']) || strlen($_POST['mName'])<1)
  {
    //required variables are empty
    die("Title is empty!");
  }


  if($_FILES['mFile']['error'])
  {
    //File upload error encountered
    die(upload_errors($_FILES['mFile']['error']));
  }

  $FileName         = strtolower($_FILES['mFile']['name']); //uploaded file name
  $FileTitle        = mysql_real_escape_string($_POST['mName']); // file title
  $ImageExt         = substr($FileName, strrpos($FileName, '.')); //file extension
  $FileType         = $_FILES['mFile']['type']; //file type
  $FileSize         = $_FILES['mFile']["size"]; //file size
  $RandNumber       = rand(0, 9999999999); //Random number to make each filename unique.
  $uploaded_date    = date("Y-m-d H:i:s");
  $username         = mysql_real_escape_string($_POST['sender']);
  $status           = "Confirmed";

  print_r($FileName);
  switch(strtolower($FileType))
  {
    //allowed file types
    case 'image/png': //png file
    case 'image/gif': //gif file
    case 'image/jpeg': //jpeg file
    case 'application/pdf': //PDF file
    case 'application/msword': //ms word file
    case 'application/vnd.ms-excel': //ms excel file
    case 'application/x-zip-compressed': //zip file
    case 'text/plain': //text file
    case 'text/html': //html file
      break;
    default:
      die('Unsupported File!'); //output error
  }

  //File Title will be used as new File name
  $NewFileName = preg_replace(array('/\s/', '/\.[\.]+/', '/[^\w_\.\-]/'), array('_', '.', ''), strtolower($FileTitle));
  $NewFileName = $NewFileName.'_'.$RandNumber.$ImageExt;
   //Rename and save uploded file to destination folder.
   if(move_uploaded_file($_FILES['mFile']["tmp_name"], $UploadDirectory . $NewFileName ))
   {
    //connect & insert file record in database
        $dbconn = mysql_connect($dbhost, $dbuser, $dbpass)or die("Unable to connect to MySQL");
    mysql_select_db($dbname,$dbconn);

    @mysql_query("INSERT INTO uploads (image, mName, filesize,username,status, uploaded_date) VALUES ('$NewFileName', '$FileTitle','$FileSize','$username','$status','$uploaded_date')");
    mysql_close($dbconn);

    header('Location: '.$SuccessRedirect); //redirect user after success

   }else{
       die('error uploading File!');
   }
}

//function outputs upload error messages, http://www.php.net/manual/en/features.file-upload.errors.php#90522
function upload_errors($err_code) {
  switch ($err_code) {
    case UPLOAD_ERR_INI_SIZE:
        return 'The uploaded file exceeds the upload_max_filesize directive in php.ini';
    case UPLOAD_ERR_FORM_SIZE:
        return 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form';
    case UPLOAD_ERR_PARTIAL:
        return 'The uploaded file was only partially uploaded';
    case UPLOAD_ERR_NO_FILE:
        return 'No file was uploaded';
    case UPLOAD_ERR_NO_TMP_DIR:
        return 'Missing a temporary folder';
    case UPLOAD_ERR_CANT_WRITE:
        return 'Failed to write file to disk';
    case UPLOAD_ERR_EXTENSION:
        return 'File upload stopped by extension';
    default:
        return 'Unknown upload error';
  }
}
?>

0 个答案:

没有答案