我正在尝试从php脚本上传文件的一个页面(imageupload.php)中检索文件名,我想在javascript函数(QandATable.php)中的另一个页面中显示它。但我不知道如何正确执行此操作,因为我一直收到无效的正则表达式标志w错误。如何修复此错误并显示从php脚本中将$_SESSION['fileImage']['name']
从imageupload.php页面检索到QandATable.php中的stopUploadImage javascript函数。
下面是php脚本,它将文件上传到服务器(imageupload.php):这是$_SESSION['fileImage']['name'] = $_FILES['fileImage']['name'];
出现的位置。
<?php
session_start();
$result = 0;
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.window.stopImageUpload(<?php echo $result;?>);
</script>
下面是我要检索$_SESSION['fileImage']['name'] = $_FILES['fileImage']['name'];
的javascript代码,但是它给了我无效的正则表达式标志w错误。
function stopImageUpload(success){
var imagename = <?php echo json_encode($_SESSION['fileImage']['name']); ?>;
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;
}