2
當我打開網頁時,它只顯示一個空白頁。你知道它爲什麼這樣做嗎?難道是因爲$ _SESSION中的[]?在錯誤控制檯上沒有javascript錯誤,我不在屏幕上顯示php錯誤。當我打開它時,它顯示一個空白網頁
下面是其中追加發生的JavaScript代碼:
<?php
session_start();
$idx = count($_SESSION ['fileImage'] - 1);
$output = isset($_SESSION ['fileImage'][$idx]) ? $_SESSION ['fileImage'][$idx]['name'] : "";
?>
function stopImageUpload(success){
var imageNameArray = ['<?php echo $output ?>'];
var result = '';
if (success == 1){
result = '<span class="msg">The file was uploaded successfully!</span><br/><br/>';
for(var i=0;i<imageNameArray.length;i++)
{
$('.listImage').append(imageNameArray[i]+ '<br/>');
}
}
else {
result = '<span class="emsg">There was an error during file upload!</span><br/><br/>';
}
return true;
}
下面是PHP腳本它文件上載這是另一個頁上從上面的javascript函數:
<?php
session_start();
$result = 0;
$errors = array();
$dirImage = "ImageFiles/";
if (isset ($_FILES ['fileImage']) && $_FILES ["fileImage"] ["error"] == UPLOAD_ERR_OK) {
$fileName = $_FILES ['fileImage'] ['name'];
$fileExt = pathinfo ($fileName, PATHINFO_EXTENSION);
$fileExt = strtolower ($fileExt);
$fileDst = $dirImage . DIRECTORY_SEPARATOR . $fileName;
if (count ($errors) == 0) {
if (move_uploaded_file ($fileTemp, $fileDst)) {
$result = 1;
}
}
}
$_SESSION ['fileImage'][] = array('name' => $_FILES ['fileImage']['name']);
?>
<script language="javascript" type="text/javascript">window.top.stopImageUpload(<?php echo $result;?>);</script>
功能stopImageUpload()沒有返回變量結果的價值......使輸出將無處可去。 – Zuul 2012-04-28 12:59:59