I have a JavaScript function below where it displays a message after file uploading is complete:
function stopVideoUpload(success) {
var namevideofile = $('.fileVideo').val();
var result = '';
if (success == 1) {
result = '<span class="msg">The file was uploaded successfully!</span><br/><br/>';
$('.listVideo').append(namevideofile + '<br/>');
}
else {
result = '<span class="emsg">There was an error during file upload!</span><br/><br/>';
}
return true;
}
Below is the php script which is on another page which successfully uploads the files:
if( file_exists("VideoFiles/".$_FILES['fileVideo']['name'])) {
$parts = explode(".",$_FILES['fileVideo']['name']);
$ext = array_pop($parts);
$base = implode(".",$parts);
$n = 2;
while( file_exists("ImageFiles/".$base."_".$n.".".$ext)) $n++;
$_FILES['fileVideo']['name'] = $base."_".$n.".".$ext;
move_uploaded_file($_FILES["fileVideo"]["tmp_name"],
"VideoFiles/" . $_FILES["fileVideo"]["name"]);
$result = 1;
}
else
{
move_uploaded_file($_FILES["fileVideo"]["tmp_name"],
"VideoFiles/" . $_FILES["fileVideo"]["name"]);
$result = 1;
}
?>
<script language="javascript" type="text/javascript">window.top.window.stopImageUpload(<?php echo $result;?>);</script>
Now except having var namevideofile to retrieve the value from the file input value (.fileVideo is the class for the file input), what I want it to do is that when the uploading is complete, the name given to file in the server would be var namevideofile. So if I have 2 files known as video.png, as I stated in my php code that if file exists then add a number to end of file name so that would create video.png and video1.png in server.
So when I append namevideofile, it should display video.png and video1.png after uploading is completed for both files. The problem with var namevideofile = $('.fileVideo').val();, is that it displays both file names as video.png which is incorrect.
So does anyone know how to change var namevideofile so that it retrieves the file name from the server after uploading? The issue is that the php script is on a separate page (videoupload.php) to the JS function (QandATable.php) so does ajax need to be involved here or not.
Anyone who could provide an example of how this can be coded would be very helpful to me 🙂
you can
echoand store the value in a javaScript variable: