JScript上传插件的问题

时间:2017-11-03 16:56:44

标签: javascript php jquery html file-upload

所以我试图将mp3和mp4文件上传到我的服务器,但它似乎没有上传。该插件上传所有其他格式,但MP3和MP4,它显示它上传MP3和MP4格式,但当我检查服务器时,文件不存在,因为他们没有上传。我正在使用drpozone.js插件。它有点冗长所以我不能在下面键入它所以我将把链接放在下面。

这是我的上传页面(index.html):

<!DOCTYPE html>
<!--[if IE 8 ]><html class="no-js oldie ie8" lang="en"> <![endif]-->
<!--[if IE 9 ]><html class="no-js oldie ie9" lang="en"> <![endif]-->
<!--[if (gte IE 9)|!(IE)]><!--><html class="no-js" lang="en"> <!--<![endif]-->
<head>

   <!--- basic page needs
   ================================================== -->
   <meta charset="utf-8">
	<title>Samuel NewDay</title>
	<meta name="description" content="">  
	<meta name="author" content="">

   <!-- mobile specific metas
   ================================================== -->
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

 	<!-- CSS
   ================================================== -->
   <link rel="stylesheet" href="css/base.css">
   <link rel="stylesheet" href="css/vendor.min.css">
   <link rel="stylesheet" href="css/main.css">
   <link rel="stylesheet" href="css/dropzone.css" />     

   <!-- script
   ================================================== -->
	<script src="js/modernizr.js"></script>
	<script src="js/dropzone.js"></script>

   <!-- favicons
	================================================== -->
	<link rel="shortcut icon" href="favicon.png" >

</head>

<body>

	<!-- header
   ================================================== -->
   <header id="main-header">

   	<div class="row">

	      <div class="logo">
	         <a href="index.html">Samuel Newday</a>
	      </div>

	      <nav id="nav-wrap">         
	         
	         <a class="mobile-btn" href="#nav-wrap" title="Show navigation">
	         	<span class="menu-icon">Menu</span>
	         </a>
         	<a class="mobile-btn" href="#" title="Hide navigation">
         		<span class="menu-icon">Menu</span>
         	</a>            

	         <ul id="nav" class="nav">
	            <li><a class="smoothscroll" href="#eps">Upload Albums/EPs.</a></li>
		         <li class="current"><a class="smoothscroll" href="#singles">Singles.</a></li>
	            <li><a class="smoothscroll" href="##photos">Photoshoots.</a></li>
	            <li><a class="smoothscroll" href="#events">Events.</a></li>
	         </ul> <!-- end #nav -->

	      </nav> <!-- end #nav-wrap -->

	      <ul class="header-social">
	        	<li><a href="#"><i class="fa fa-facebook"></i></a></li>
	        	<li><a href="#"><i class="fa fa-twitter"></i></a></li>
	        	<li><a href="#"><i class="fa fa-google-plus"></i></a></li>
	      </ul>      

	   </div>

   </header> <!-- end header -->
   <!-- homepage
   ================================================== -->
   <section id="top">	
		<div class="row hero-content">
			<div class="twelve columns hero-container">
			   <!-- hero-slider start-->
			   <div id="hero-slider" class="flexslider">
				   <ul class="slides">
					   <!-- slide -->
					   <li>
						   <div class="flex-caption">
								<h1 class="">Admin Backend</h1>
								<h3 class="" style="color: white">Here you can upload <a class="smoothscroll" href="#eps" title="portfolio" >Albums/EPs</a>, <a class="smoothscroll" href="#singles" title="portfolio" >Singles</a>, <a class="smoothscroll" href="#photos" title="portfolio" >Photoshoots</a> and <a class="smoothscroll" href="#events" title="portfolio" >Upcoming Events!</a><br />You can also edit some of the website's information here!</h3>			   
							</div>
					   </li>					              
				   </ul>
			   </div> <!-- end hero-slider -->				   
	      </div> <!-- end twelve columns-->
		</div> <!-- end row -->	
		<div id="more">
		      <a class="smoothscroll" href="#eps">Manage Site<i class="fa fa-angle-down"></i></a>
		</div> 	
   </section> <!-- end homepage hero -->

     <!-- Album/EP Upload Section
   ================================================== -->
   <section id="Section1">
   	<div class="row section-head">
      	<div class="twelve columns">
      		<h1>Upload Album/EP<span>.</span></h1>
	         <hr />     	    
	         <p>Upload Album/EP according to the steps below.</p>
	      </div> <!-- end section-head -->
      </div>
      <div class="row mobile-no-padding">       	
      	<div class="process bgrid-half tab-bgrid-whole group">
      		<div class="bgrid">
			      <h3>Album/EP Artwok.</h3>	
			      <p>
                      <div class="image_upload_div">
                          <form action="upload.php" class="dropzone">
                          </form>
                      </div>
			      </p>
		   	</div>
      		<div class="bgrid">
			     	<h3>Tracks.</h3>
			     	<p>
                     <div class="image_upload_div">
                          <form action="upload.php" class="dropzone">
                          </form>
                      </div>
			     	</p>	
		      </div>
      	</div> <!-- end process -->      	
     	</div> <!-- end row -->
   </section> <!-- end album/ep upload -->
   
   <!-- Footer
   ================================================== -->
   <footer>

      <div class="row">  

      	<div class="twelve columns content group">
      		
				<ul class="social-links">
               <li><a href="#"><i class="fa fa-facebook-square"></i></a></li>
               <li><a href="#"><i class="fa fa-twitter-square"></i></a></li>
               <li><a href="#"><i class="fa fa-google-plus-square"></i></a></li>               
               <li><a href="#"><i class="fa fa-youtube-play"></i></a></li>
               <li><a href="#"><i class="fa fa-vimeo-square"></i></a></li>
               <li><a href="#"><i class="fa fa-flickr"></i></a></li>               
               <li><a href="#"><i class="fa fa-skype"></i></a></li>
            </ul>

            <hr />

      	</div>           

         <ul class="copyright">
         	<li>&copy; Copyright 2017 Samuel NewDay.</li> 
         </ul>

         <div id="go-top">
            <a class="smoothscroll" title="Back to Top" href="#top">Back to Top<i class="fa fa-angle-up"></i></a>
         </div>

      </div> <!-- end row -->

   </footer> <!-- end footer -->

   <div id="preloader"> 
    	<div id="loader"></div>
   </div> 

   <!-- Java Script
   ================================================== --> 
   <script src="js/jquery-1.11.3.min.js"></script>
   <script src="js/jquery-migrate-1.2.1.min.js"></script>
   <script src="js/jquery.flexslider-min.js"></script>
   <script src="js/jquery.waypoints.min.js"></script>
   <script src="js/jquery.validate.min.js"></script>
   <script src="js/jquery.fittext.js"></script>
   <script src="js/jquery.placeholder.min.js"></script>
   <script src="js/jquery.magnific-popup.min.js"></script>  
   <script src="js/main.js"></script>

</body>

</html>

这是upload.php文件:

<?php
if(!empty($_FILES)){
	
	//database configuration
	$dbHost = 'localhost';
	$dbUsername = 'root';
	$dbPassword = '';
	$dbName = 'uploads';
	//connect with the database
	$conn = new mysqli($dbHost, $dbUsername, $dbPassword, $dbName);
	if($mysqli->connect_errno){
		echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
	}
	
	$targetDir = "uploads/";
	$fileName = $_FILES['file']['name'];
	$targetFile = $targetDir.$fileName;
	if(move_uploaded_file($_FILES['file']['tmp_name'],$targetFile)){
		//insert file information into db table
		$conn->query("INSERT INTO files (file_name, uploaded) VALUES('".$fileName."','".date("Y-m-d H:i:s")."')");
	}
	
}
?>

Dropzone的JScript文件可以在以下链接中找到:

Dropzone Link

请让我知道如何上传mp3和mp4格式。谢谢。

1 个答案:

答案 0 :(得分:0)

如果您要上传文件,则必须将enctype的{​​{1}}设置为form,否则文件上传不会发生(iirc将文件名作为文件)。请查看https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form以获得一个很好的参考。这里讨论了multipart/form-data属性。