我正在尝试从一个页面中的 php 脚本接收文件的名称,并将其附加到单独页面上的 javascript 函数中。问题是我在我的错误控制台中收到一个无效的正则表达式标志 w 错误,该错误声明未定义变量:'fileimagename for the line below:
var nameimagefile = <?php echo $fileimagename; ?>;
我该如何解决这个错误?
下面是javascript函数(QandATable.php):
function stopImageUpload(success){
var nameimagefile = <?php echo $fileimagename; ?>;
var result = '';
if (success == 1){
result = '<span class="msg">The file was uploaded successfully!</span><br/><br/>';
$('.listImage').append(nameimagefile + '<br/>');
}
else {
result = '<span class="emsg">There was an error during file upload!</span><br/><br/>';
}
return true;
}
以下是位于文件名的单独页面(imageupload.php)上的php代码:
<?php
session_start();
if (isset($_POST['fileimagename'])) {
$_SESSION['fileimagename'] = $_SESSION[' $_FILES['fileImage']['name']'];
}
if( file_exists("ImageFiles/".$_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>