search
HomeBackend DevelopmentPHP Tutorialwindows 下jquery+ajax+php文件上传,linux下,出问题.

windows 下jquery+ajax+php文件上传,linux+nginx+php+mysql 出问题.....  有个选择文件路径后js检测后缀的也不弹出了,提交后到不了 接受不到任何东西....wnmp下写的。


回复讨论(解决方案)

你给出的信息实在是太少了

windows 下jquery+ajax+php文件上传,linux+nginx+php+mysql 出问题.....  有个选择文件路径后js检测后缀的也不弹出了,提交后到不了 接受不到任何东西....wnmp下写的。
              
                  jquery
                  windows
          ……

html 

<?php		/******************************************	ajax上传入口	******************************************/?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>导入程序</title><link href="styles/general.css" rel="stylesheet" type="text/css" /><link href="styles/main.css" rel="stylesheet" type="text/css" /><!--<link href="ajaxfileupload.css" type="text/css" rel="stylesheet">--><script type="text/javascript" src="Excel/jquery.js"></script><script type="text/javascript" src="Excel/ajaxfileupload.js"></script><script type="text/javascript">	function ajaxFileUpload()	{		var f_content = form.fileToUpload.value; 		var fileext=f_content.substring(f_content.lastIndexOf("."),f_content.length) 			fileext=fileext.toLowerCase() 		if(fileext == '')		{			alert('先选择文件');			return false;		}		if (fileext!='.csv') 		{ 			 alert("导入的文件,必须csv格式,重新选择!");    			 return false; 		}		$("#loading")		.ajaxStart(function(){			$(this).show();		})		.ajaxComplete(function(){			$(this).hide();		});		$.ajaxFileUpload		(			{				url:'buy_clothes_day_insert.php',				secureuri:false,				fileElementId:'fileToUpload',				dataType: 'json',				data:{name:'logan', id:'id'},				success: function (data, status)				{					if(typeof(data.error) != 'undefined')					{						/*						if(data.error != '')						{							alert(data.error);						}						else						{								alert(data.msg);						}*/						//50条插入完						if(data.msg == 1)						{							repeat_do_ajax();						}else if(data.msg == 2){							alert('无数据');						}					}				},				error: function (data, status, e)				{					//第一次post失败					alert(e);				}			}		)		return false;	}		function repeat_do_ajax()	{		$.ajax({			//url:"doajaxfileupload.php",			url:"buy_clothes_day_insert.php",			type:"GET",			dataType: 'json',			data:{act:'input'},			success:function(data, status)			{					//还有数组重复ajax				if(data.msg == 1){					//setInterval(repeat_do_ajax,1000);					repeat_do_ajax();				}else if(data.msg == 0){					alert('成功导入本次所有数据!');				}							},			error:function(data, status)			{				//防止数据库超时30后在继续				if(status == 'parsererror' || data.error == 'undefined')					repeat_do_ajax();				//setInterval(repeat_do_ajax,3000);			}		})		}</script>	</head><body><div id="wrapper">    <div id="content">    	<h2 id="导入程序">导入程序</h2>    	    			<img  src="/static/imghwm/default1.png"  data-src="Excel/loading.gif"  class="lazy"  id="loading"    style="max-width:90%" alt="windows 下jquery+ajax+php文件上传,linux下,出问题." >		<form name="form" action="" method="POST" enctype="multipart/form-data">			<table cellpadding="0" cellspacing="0" class="tableForm"  style="max-width:90%">			<thead>				<tr>					<th>选择csv文件</th>				</tr>			</thead>			<tbody>					<tr>					<td><input id="fileToUpload" type="file" size="45" name="fileToUpload" class="input"></td>				</tr>			</tbody>				<tfoot>					<tr>						<td><button class="button" id="buttonUpload" onclick="return ajaxFileUpload();">执行</button></td>					</tr>				</tfoot>		</table>				</form>    	    </div></div>    </body></html>


php
<?php		/*do ajax */	date_default_timezone_set('Asia/Shanghai');		//第二次GET ajax请求 直接重复导入	if($_REQUEST['act'] == 'input')	{		return_show('0',check_data());	}	$error = "";	$msg = "";	$fileElementName = 'fileToUpload';	if(!empty($_FILES[$fileElementName]['error']))	{		switch($_FILES[$fileElementName]['error'])		{			case '1':				$error = 'The uploaded file exceeds the upload_max_filesize directive in php.ini';				break;			case '2':				$error = 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form';				break;			case '3':				$error = 'The uploaded file was only partially uploaded';				break;			case '4':				$error = 'No file was uploaded.';				break;			case '6':				$error = 'Missing a temporary folder';				break;			case '7':				$error = 'Failed to write file to disk';				break;			case '8':				$error = 'File upload stopped by extension';				break;			case '999':			default:				$error = 'No error code avaiable';		}	}elseif(empty($_FILES['fileToUpload']['tmp_name']) || $_FILES['fileToUpload']['tmp_name'] == 'none')	{		$error = 'No file was uploaded..';	}else 	{		$msg .= " File Name: " . $_FILES['fileToUpload']['name'] . ", ";		$msg .= " File Size: " . @filesize($_FILES['fileToUpload']['tmp_name']);		//删除临时文件		//@unlink($_FILES['fileToUpload']);				read_csv($_FILES['fileToUpload']['tmp_name']);			}		/*读取*/	function read_csv($filename)	{		$row = array();		$key = 0;		setlocale(LC_ALL,array('zh_CN.gbk','zh_CN.gb2312','en_US.utf8'));		$handle=fopen($filename,'r');		//$a = _fgetcsv($handle,1000,',','"');		while(!feof($handle) && $data=fgetcsv($handle,1000,','))		{			$num = count($data);			for($i = 0; $i < $num; $i++)			{ 				//if(!empty($data[$i]))					$row[$key][$i] = iconv('GBK','utf-8',trim($data[$i]));							} 			$key++; 		}		fclose($handle);		if(empty($row))		{			return_show(2,2);		}else{                         //作insert			$num = del_incomplete($row);			//echo "<script>alert('Sucessed Input orderNum ".$num." !');</script>";					}			}	?>

你能确认 js 代码被执行了吗?

你能确认 js 代码被执行了吗?
执行了js方法外面的alert可以弹 刚看到有个js undefined 以为大小写呢 还没找到问题

凭借我多年的经验判断...应该是JS问题.
你2个平台浏览器是否一致..浏览器是否一样.
var f_content = form.fileToUpload.value; 
form能直接用?我感觉这种简写出的问题 

然后 在看 是JS问题 还是PHP问题..
取消JS判断 试试可否上传成功.ajax触发处alert(1) ajax执行成功返回处alert(2)


分开测试方能解决问题

很有可能是 大小写的问题

单独来完成测试:
1、判断js获取表单对象是否成功;
2、判断提交结果的反馈,比如表单中不提交文件,只POST数据,判断PHP后端的POST全局数组的输出;
3、使用去掉JS之后的表单提交,看是否成功;
4、使用去掉JS之后的文件上传,看是否成功;(确保linux服务器上对应的目录有写权限)

凭借我多年的经验判断...应该是JS问题.
你2个平台浏览器是否一致..浏览器是否一样.
var f_content = form.fileToUpload.value; 
form能直接用?我感觉这种简写出的问题 

然后 在看 是JS问题 还是PHP问题..
取消JS判断 试试可否上传成功.ajax触发处alert(1) ajax执行成功返回处alert(……

这个var f_content = form.fileToUpload.value; 改了
现在还报错是:Uncaught SyntaxError: Unexpected end of input
chrome ie 都有...

解决了 因为返回json类型 不会返回具体错误 所以js改jquery取值后是没问题 (win下本来就没问题的),查到最后是因为运维的没建立对应表插不进报错。建表后一切正常了, 谢谢大家~~

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Working with Flash Session Data in LaravelWorking with Flash Session Data in LaravelMar 12, 2025 pm 05:08 PM

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

cURL in PHP: How to Use the PHP cURL Extension in REST APIscURL in PHP: How to Use the PHP cURL Extension in REST APIsMar 14, 2025 am 11:42 AM

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Simplified HTTP Response Mocking in Laravel TestsSimplified HTTP Response Mocking in Laravel TestsMar 12, 2025 pm 05:09 PM

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

12 Best PHP Chat Scripts on CodeCanyon12 Best PHP Chat Scripts on CodeCanyonMar 13, 2025 pm 12:08 PM

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Explain the concept of late static binding in PHP.Explain the concept of late static binding in PHP.Mar 21, 2025 pm 01:33 PM

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

PHP Logging: Best Practices for PHP Log AnalysisPHP Logging: Best Practices for PHP Log AnalysisMar 10, 2025 pm 02:32 PM

PHP logging is essential for monitoring and debugging web applications, as well as capturing critical events, errors, and runtime behavior. It provides valuable insights into system performance, helps identify issues, and supports faster troubleshoot

How to Register and Use Laravel Service ProvidersHow to Register and Use Laravel Service ProvidersMar 07, 2025 am 01:18 AM

Laravel's service container and service providers are fundamental to its architecture. This article explores service containers, details service provider creation, registration, and demonstrates practical usage with examples. We'll begin with an ove

Customizing/Extending Frameworks: How to add custom functionality.Customizing/Extending Frameworks: How to add custom functionality.Mar 28, 2025 pm 05:12 PM

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.