海 我有包含這樣動態生成的文件上傳控件<使用javascript>不發佈?
<tr><td> <input name="ufile[]" type="file" id="ufile[]" size="50" /></td></tr>
在文件類型的表單提交我打電話的腳本
function addRowToTable()
{
var tbl = document.getElementById('uploadTab');
var lastrow = tbl.rows.length;
var iteration = lastrow;
var row = tbl.insertRow(lastrow);
var cell2 = row.insertCell(0);
var e2 = document.createElement('input');
e2.type = 'file';
e2.name = 'ufile[]';
e2.id = 'ufile[]';
e2.size='50';
cell2.appendChild(e2);
}
這個腳本生成按鈕上的TR點擊......在我鑑於generatedsource工具,我得到了「」像這樣
<tr><td><input size="50" id="ufile[]" name="ufile[]" type="file"></td></tr>
當我提交表單我不爲生成的文件類型得到的文件名我n我的查看頁面 但是我得到的文件名是默認的文件名 可能是什麼問題?
我張貼我的表格此頁,
<?php
//set where you want to store files
//in this example we keep file in folder upload
//$HTTP_POST_FILES['ufile']['name']; = upload file name
//for example upload file name cartoon.gif . $path will be upload/cartoon.gif
$path1= "upload/".$HTTP_POST_FILES['ufile']['name'][0];
$path2= "upload/".$HTTP_POST_FILES['ufile']['name'][1];
$path3= "upload/".$HTTP_POST_FILES['ufile']['name'][2];
$path4= "upload/".$HTTP_POST_FILES['ufile']['name'][3];
//copy file to where you want to store file
copy($HTTP_POST_FILES['ufile']['tmp_name'][0], $path1);
copy($HTTP_POST_FILES['ufile']['tmp_name'][1], $path2);
echo copy($HTTP_POST_FILES['ufile']['tmp_name'][2], $path3);
//$HTTP_POST_FILES['ufile']['name'] = file name
//$HTTP_POST_FILES['ufile']['size'] = file size
//$HTTP_POST_FILES['ufile']['type'] = type of file
echo "File Name :".$HTTP_POST_FILES['ufile']['name'][0]."<BR/>";
echo "File Size :".$HTTP_POST_FILES['ufile']['size'][0]."<BR/>";
echo "File Type :".$HTTP_POST_FILES['ufile']['type'][0]."<BR/>";
echo "<img src=\"$path1\" width=\"150\" height=\"150\">";
echo "<P>";
echo "File Name :".$HTTP_POST_FILES['ufile']['name'][1]."<BR/>";
echo "File Size :".$HTTP_POST_FILES['ufile']['size'][1]."<BR/>";
echo "File Type :".$HTTP_POST_FILES['ufile']['type'][1]."<BR/>";
echo "<img src=\"$path2\" width=\"150\" height=\"150\">";
echo "<P>";
echo "File Name :".$HTTP_POST_FILES['ufile']['name'][2]."<BR/>";
echo "File Size :".$HTTP_POST_FILES['ufile']['size'][2]."<BR/>";
echo "File Type :".$HTTP_POST_FILES['ufile']['type'][2]."<BR/>";
echo "<img src=\"$path3\" width=\"150\" height=\"150\">";
///////////////////////////////////////////////////////
// Use this code to display the error or success.
$filesize1=$HTTP_POST_FILES['ufile']['size'][0];
$filesize2=$HTTP_POST_FILES['ufile']['size'][1];
$filesize3=$HTTP_POST_FILES['ufile']['size'][2];
if($filesize1 && $filesize2 && $filesize3 != 0)
{
echo "We have recieved your files";
}
else {
echo "ERROR.....";
}
//////////////////////////////////////////////
// What files that have a problem? (if found)
if($filesize1==0) {
echo "There're something error in your first file";
echo "<BR />";
}
if($filesize2==0) {
echo "There're something error in your second file";
echo "<BR />";
}
if($filesize3==0) {
echo "There're something error in your third file";
echo "<BR />";
}
?>
編輯 這是我的數組
Array ([ufile] => Array ([name] => Array ([0] => stripe.jpg [1] => stripe.jpg) [type] => Array ([0] => image/jpeg [1] => image/jpeg) [tmp_name] => Array ([0] => D:\xampp\tmp\php29A9.tmp [1] => D:\xampp\tmp\php29AA.tmp) [error] => Array ([0] => 0 [1] => 0) [size] => Array ([0] => 8717 [1] => 8717)))
因此,'$ _FILES'數組的完整轉儲沒有顯示任何第二個文件的提示? – 2010-04-28 07:11:52
@Pekka看看我的編輯... – udaya 2010-04-28 07:13:42
你可以做一個'print_r($ _ FILES)'並且一併發佈?您的腳本按順序排列,但只是爲了確保。 – 2010-04-28 07:14:31