我在下面有一个javascript函数,当文件上传完成后,它会显示必要的消息:
function stopImageUpload(success){
var imagename = <?php echo json_encode($imagename); ?>;
var result = '';
if (success == 1){
result = '<span class="msg">The file was uploaded successfully!</span><br/><br/>';
$('.listImage').append(imagename + '<br/>');
}
else {
result = '<span class="emsg">There was an error during file upload!</span><br/><br/>';
}
return true;
}
现在我正在尝试检索下面的$ _SESSION变量,然后使用上面的javascript函数(在单独的页面上)将$ _SESSION称为'$ imagename',然后将其附加到.list。
但我的问题是如何编写上面的if issett语句,以便它可以判断下面的$ _SESSION变量是否已设置,以便我可以使用$ imagename来检索会话?
下面是php脚本,其中包含$ _SESSION以及文件上传的位置:
if (isset($_POST['fileImage'])) {
$_SESSION['imagename'] = $_FILES['fileImage']['name'];
if( file_exists("ImageFiles/".$_FILES['fileImage']['name'])) {
$_SESSION['fileImage']['name'] = $_FILES['fileImage']['name'];
$parts = explode(".",$_FILES['fileImage']['name']);
$ext = array_pop($parts);
$base = implode(".",$parts);
$n = 2;
while( file_exists("ImageFiles/".$base."_".$n.".".$ext)) $n++;
$_FILES['fileImage']['name'] = $base."_".$n.".".$ext;
move_uploaded_file($_FILES["fileImage"]["tmp_name"],
"ImageFiles/" . $_FILES["fileImage"]["name"]);
$result = 1;
}
else
{
move_uploaded_file($_FILES["fileImage"]["tmp_name"],
"ImageFiles/" . $_FILES["fileImage"]["name"]);
$result = 1;
}
}
?>
<script language="javascript" type="text/javascript">
window.top.stopImageUpload(<?php echo "'$result'";?>);</script>
答案 0 :(得分:0)
尝试
var imagename = <?php if (isset($_SESSION['imagename'])) echo json_encode($_SESSION['imagename']); ?>;