I have a javascript function below where when a file has finished uploading, it will display the neccessary messages:
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;
}
Now I am trying to retrieve the $_SESSION variable below and then use the javascript function above (which is on a seperate page) to call the $_SESSION as ‘$imagename’ and then append it into .list.
But my question is how do I write the if issett statement above so it can tell if the $_SESSION variable below is set so then I can use $imagename to retrieve the session?
Below is php script where it contains the $_SESSION and where files are uploaded:
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>
Try