javascript - PHP upload with dynamic url by action attribute. -
i trying upload matlab file using php onto server. need pass file part of php url can take out url , pass on code in custom shell script.
here script using alter url file not uploading.
html code:
<script type="text/javascript"> window.onload = function(){ var form = document.getelementbyid("phpform"); form.onsubmit = function(){ var matlabfile = document.getelementbyid("filetoupload"); var filename = matlabfile.value; var filename2=filename.replace(/^.*\\/, ""); var filename3=filename2.substr(0, filename2.lastindexof('.')); window.location = "upload.php?matlabfile=" + filename3 homecoming false; }; }; </script> <form action="" id="phpform" method="post" name="phpform" enctype="multipart/form-data> <table style=" text-align:center;"> <tr> <td><b>file 1:</b> <input id= "filetoupload" name="filetoupload" type="file"></td> </tr> <tr> <td><input name="submit" type= "submit" value= "upload script"></td> </tr> </table> </form>
php code:
<?php $targetfolder = ""; $targetfolder = $targetfolder . basename( $_files['filetoupload']['name']) ; if(move_uploaded_file($_files['filetoupload']['tmp_name'], $targetfolder)) { echo "the file ". basename( $_files['filetoupload']['name']). " uploaded"; } else { echo "problem uploading file"; } $var1=$_get['matlabfile']; echo "<pre>$var1</pre>"; echo "matlabfile : ".$_get['matlabfile']."<br>"; $output = shell_exec("./n.sh $var1 2>&1"); echo "<pre>$output</pre>"; ?>
could please tell me doing wrong.
looking forwards replies.
thanks , best regards, shivam dixit
your 'return false;' preventing submission of form, , file isn't uploaded. you're moving user address.
instead of
window.location = "upload.php?matlabfile=" + filename3; homecoming false;
try set form action url want:
form.setattribute('action', "upload.php?matlabfile=" + filename3);
then, user sent page want, , file uploaded :)
javascript php matlab upload action
No comments:
Post a Comment