PHP 表单上传总是“upload NOT successful”
本帖最后由 renye616 于 2013-08-08 11:21:10 编辑 <?php
include_once 'include/config.php';
include_once 'include/db.php';
include_once 'check.php';
$sss = new HAYA_check();
$applyuser = $sss->user();
//list
$username = $_REQUEST["username"];
$gender = $_REQUEST["gender"];
$testdate = ($_REQUEST["testdate"]=="") ? "0000-0-0" : $_REQUEST["testdate"];
$monaddate = ($_REQUEST["monaddate"]=="") ? "0000-0-0" : $_REQUEST["monaddate"];
$email = $_REQUEST["email"];
$tel1 = $_REQUEST["tel1"];
$tel2 = $_REQUEST["tel2"];
//$listtype = $_REQUEST["listtype"]);
$parentinfo = $_REQUEST["parentinfo"];
$studentinfo = $_REQUEST["studentinfo"];
$continueclass = $_REQUEST["continueclass"];
$studiedclassno = $_REQUEST["studiedClassno"];
$teachername = $_REQUEST["teachername"];
$consultant = $_REQUEST["consultant"];
$assistant = $_REQUEST["assistant"];
$senateclass = $_REQUEST["Senateclass"];
$senateaudit = $_REQUEST["Senateaudit"];
$classno = $_REQUEST["classno"];
$classname = $_REQUEST["classname"];
$grade = $_REQUEST["grade"];
$classsuffix = $_REQUEST["classsuffix"];
$startdate = ($_REQUEST["startdate"]=="") ? "0000-0-0" : $_REQUEST["startdate"];
$enddate = ($_REQUEST["enddate"]=="") ? "0000-0-0" : $_REQUEST["enddate"];
$classfrequency = $_REQUEST["classfrequency"];
$classplace = $_REQUEST["classplace"];
$fee = ($_REQUEST["fee"] == "") ? 0 : $_REQUEST["fee"];
$describe = $_REQUEST["describe"];
$transferfee = ($_REQUEST["transferfee"] == "") ? 0 : $_REQUEST["transferfee"];
$normalnumber = ($_REQUEST["normalnumber"] == "") ? 0 : $_REQUEST["normalnumber"];
$classroom = $_REQUEST["classroom"];
$classarrange = $_REQUEST["classarrange"];
$discount = $_REQUEST["discount"];
$discountreson1 = $_REQUEST["discountreson1"];
$discountreson2 = $_REQUEST["discountreson2"];
$discountreson3 = $_REQUEST["discountreson3"];
$unitprice = $_REQUEST["unitprice"];
$allclassfrequency = ($_REQUEST["allclassfrequency"] == "") ? 0 : $_REQUEST["allclassfrequency"];
$allclasstimes = ($_REQUEST["allclasstimes"] == "") ? 0 : $_REQUEST["allclasstimes"];
$allfee = ($_REQUEST["allfee"] == "") ? 0 : $_REQUEST["allfee"];
$teachbookapplier = $_REQUEST["teachbookapplier"];
$teachbookapplyno = $_REQUEST["teachbookapplyno"];
$lesoncardno = $_REQUEST["lesoncardno"];
$books = $_REQUEST["books"];
// course
$cl = array(
array("name"=>$_REQUEST["cl1_1"],"number"=>$_REQUEST["cl1_2"],"classtime"=>$_REQUEST["cl1_3"],"teacher"=>$_REQUEST["cl1_4"]),
array("name"=>$_REQUEST["cl2_1"],"number"=>$_REQUEST["cl2_2"],"classtime"=>$_REQUEST["cl2_3"],"teacher"=>$_REQUEST["cl2_4"]),
array("name"=>$_REQUEST["cl3_1"],"number"=>$_REQUEST["cl3_2"],"classtime"=>$_REQUEST["cl3_3"],"teacher"=>$_REQUEST["cl3_4"]),
array("name"=>$_REQUEST["cl4_1"],"number"=>$_REQUEST["cl4_2"],"classtime"=>$_REQUEST["cl4_3"],"teacher"=>$_REQUEST["cl4_4"]),
array("name"=>$_REQUEST["cl5_1"],"number"=>$_REQUEST["cl5_2"],"classtime"=>$_REQUEST["cl5_3"],"teacher"=>$_REQUEST["cl5_4"]),
array("name"=>$_REQUEST["cl6_1"],"number"=>$_REQUEST["cl6_2"],"classtime"=>$_REQUEST["cl6_3"],"teacher"=>$_REQUEST["cl6_4"]),
array("name"=>$_REQUEST["cl7_1"],"number"=>$_REQUEST["cl7_2"],"classtime"=>$_REQUEST["cl7_3"],"teacher"=>$_REQUEST["cl7_4"]),
array("name"=>$_REQUEST["cl8_1"],"number"=>$_REQUEST["cl8_2"],"classtime"=>$_REQUEST["cl8_3"],"teacher"=>$_REQUEST["cl8_4"]),
array("name"=>$_REQUEST["cl9_1"],"number"=>$_REQUEST["cl9_2"],"classtime"=>$_REQUEST["cl9_3"],"teacher"=>$_REQUEST["cl9_4"]),
array("name"=>$_REQUEST["cl10_1"],"number"=>$_REQUEST["cl10_2"],"classtime"=>$_REQUEST["cl10_3"],"teacher"=>$_REQUEST["cl10_4"])
);
// arrangetype
$arrangetype = $_REQUEST["arrangetype"];
$arrangetypestr = "";
for($i=0;$i<count($arrangetype);$i++){
if($i > 0) $arrangetypestr .= " | ";
$arrangetypestr .= $arrangetype[$i];
}
// netclass cards
$netclasscards = $_REQUEST["netclasscards"];
$netclasscardstr = "";
for($i=0;$i<count($netclasscards);$i++){
if($i > 0) $netclasscardstr .= " | ";
$netclasscardstr .= $netclasscards[$i];
}
//echo $netclasscardstr;
$uploadfilepath = "";
if($_FILES["file"]["name"] != ""){
include_once 'uploadfile.php';
if($upfilename != "" && $upfilename != null) $uploadfilepath = "upload/" . $upfilename;
}
$s = new HAYA_db();
$qinsert = "INSERT INTO JWlist (".
"username,".
"gender,".
"testdate,".
"monaddate,".
"email,".
"tel1,".
"tel2,".
//"listtype,".
"parentinfo,".
"studentinfo,".
"continueclass,".
"studiedclassno,".
"teachername,".
"consultant,".
"assistant,".
"senateclass,".
"senateaudit,".
"classno,".
"classname,".
"grade,".
"classsuffix,".
"startdate,".
"enddate,".
"classfrequency,".
"classplace,".
"fee,".
"describes,".
"transferfee,".
"normalnumber,".
"classroom,".
"arrangetype,".
"classarrange,".
"discount,".
"discountreson1,".
"discountreson2,".
"discountreson3,".
"unitprice,".
"allclassfrequency,".
"allclasstimes,".
"allfee,".
"teachbookapplier,".
"teachbookapplyno,".
"lesoncardno,".
"books,".
"netclasscards,".
"status,".
"applytime,".
"applyuser,".
"uploadfilepath".
") VALUES (".
"'" . $username . "', '" .
$gender . "', '" .
$testdate . "', '" .
$monaddate . "', '" .
$email . "', '" .
$tel1 . "', '" .
$tel2 . "', '" .
//$listtype . "', '" .
$parentinfo . "', '" .
$studentinfo . "', '" .
$continueclass . "', '" .
$studiedclassno . "', '" .
$teachername . "', '" .
$consultant . "', '" .
$assistant . "', '" .
$senateclass . "', '" .
$senateaudit . "', '" .
$classno . "', '" .
$classname . "', '" .
$grade . "','" .
$classsuffix . "', '" .
$startdate . "', '" .
$enddate . "', '" .
$classfrequency . "', '" .
$classplace . "', '" .
$fee . "', '" .
$describe . "', '" .
$transferfee . "', '" .
$normalnumber . "', '" .
$classroom . "', '" .
$arrangetypestr . "', '" .
$classarrange . "', '" .
$discount . "', '" .
$discountreson1 . "', '" .
$discountreson2 . "', '" .
$discountreson3 . "', '" .
$unitprice . "', '" .
$allclassfrequency . "', '" .
$allclasstimes . "', '" .
$allfee . "', '" .
$teachbookapplier . "', '" .
$teachbookapplyno . "', '" .
$lesoncardno . "', '" .
$books . "', '" .
$netclasscardstr . "', '" .
"1',".
"now(),'".
$applyuser."','".
$uploadfilepath . "'" .
")";
//echo $qinsert;
$resultstr = $s->query($qinsert);
$lastId = $s->getLastInsertId();
if(!$resultstr) echo '<script language="javascript">alert("Upload NOT successful!");history.go(-1);</script>';
else{
//$q2 = "SELECT MAX(ID) FROM JWlist";
//$rsID = $s->query($q2);
//echo $lastId;
//echo "cl count : ".count($cl);
for($i=0;$i<count($cl);$i++){
if($cl[$i]["name"] == null || $cl[$i]["name"] == "") continue;
$qinsert2 = "INSERT INTO course (".
"listID,".
"name,".
"number,".
"classtime,".
"teacher".
") VALUES (".
"'" . $lastId . "', '" .
$cl[$i]["name"] . "', '" .
$cl[$i]["number"] . "', '" .
$cl[$i]["classtime"] . "', '" .
$cl[$i]["teacher"] . "'" .
")";
//echo $qinsert2;
$result2 = $s->query($qinsert2);
if(!$result2) echo "false";
else echo "true";
}
echo '<script language="javascript">alert("Upload successful!");history.go(-1);</script>';
}
//echo '<script language="javascript">history.go(-1);</script>';
?>
====================== ================
=============php 配置文件=======================
;;;;;;;;;;;;;;;;
; File Uploads ;
;;;;;;;;;;;;;;;;
; Whether to allow HTTP file uploads.
; http://www.php.net/manual/en/ini.core.php#ini.file-uploads
file_uploads = On
; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
; http://www.php.net/manual/en/ini.core.php#ini.upload-tmp-dir
upload_tmp_dir = /var/www/html/upload
; Maximum allowed size for uploaded files.
; http://www.php.net/manual/en/ini.core.php#ini.upload-max-filesize
upload_max_filesize = 10M PHP 上传 JavaScript
[解决办法]
utf8_general_ci 只是说内容按 utf8 存储,不表示你给他的数据是正确的
除非你在安装 mysql 时做了字符集设置(即便做了也不见得就是utf8的),否则都是 latin1 的
所以都应该有执行 set names 页面编码
[解决办法]
$resultstr = $s->query($qinsert);
输出$resultstr瞧瞧。