I have this code below and the problem is that it is not uploading the file and the call back javascript function at the bottom isn't displaying the result. Now before I entered in the if isset ($_POST[fileImage'])... code, and the $_SESSION['fileImage']['name'] = $_FILES['fileImage']['name'];
, then the files uploaded perfectly.But with those 2 pieces of code, it has stopped the uploading from happening.
So I believe the problem is that the code above I have used have been placed in the wrong places. How can the code below be placed correctly in the right places for the uploading to start working again?
Below is the code which is suppose to upload the files but fails:
<?php
$result = 0;
if (isset($_POST['fileImage']) && ((($_FILES["fileImage"]["type"] == "image/gif")
|| ($_FILES["fileImage"]["type"] == "image/jpeg")
|| ($_FILES["fileImage"]["type"] == "image/pjpeg")
|| ($_FILES["fileImage"]["type"] == "image/jpg")
|| ($_FILES["fileImage"]["type"] == "image/png")
|| ($_FILES["fileImage"]["type"] == "image/tif"))){
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.stopImageUpload(<?php echo $result;?>);
</script>
<?php
}
$_SESSION['fileImage']['name'] = $_FILES['fileImage']['name'];
?>