Home > Backend Development > PHP Tutorial > javascript - php文件里js不能被执行

javascript - php文件里js不能被执行

WBOY
Release: 2016-06-06 20:51:09
Original
1972 people have browsed it

我想把上传文件路径返回到前端保存,但是后台php文件里的js没有执行,前台input标签里的value值一直为空
后台acceptfile.php代码如下:

<?php if(!isset($_REQUEST['filename']))
   {
     exit('No file');
   }
   else{
   $upload_path = dirname(__FILE__).'/audio';
   date_default_timezone_set("Asia/Shanghai");
   $filename = $_REQUEST['filename'].rand(0,10000).date('YmdHis');

   $fp = fopen($upload_path."/".$filename.".wav", "wb");
   $audiosrc=$upload_path."/".$filename.".wav";
   echo "<script language='javascript'>parent.send_form.audiosrc.value='$audiosrc';";
  echo "<script language="javascript">alert('上传成功');</script>";
   fwrite($fp, file_get_contents('php://input'));   
   fclose($fp);
   exit('done');
  }
   
?>
Copy after login
Copy after login

前端index.php里form表单:

Copy after login
Copy after login
...

请问问题出在哪,文件是有保存到相应的文件夹里的,就是路径没法返回到前端form表单里

回复内容:

我想把上传文件路径返回到前端保存,但是后台php文件里的js没有执行,前台input标签里的value值一直为空
后台acceptfile.php代码如下:

<?php if(!isset($_REQUEST['filename']))
   {
     exit('No file');
   }
   else{
   $upload_path = dirname(__FILE__).'/audio';
   date_default_timezone_set("Asia/Shanghai");
   $filename = $_REQUEST['filename'].rand(0,10000).date('YmdHis');

   $fp = fopen($upload_path."/".$filename.".wav", "wb");
   $audiosrc=$upload_path."/".$filename.".wav";
   echo "<script language='javascript'>parent.send_form.audiosrc.value='$audiosrc';";
  echo "<script language="javascript">alert('上传成功');</script>";
   fwrite($fp, file_get_contents('php://input'));   
   fclose($fp);
   exit('done');
  }
   
?>
Copy after login
Copy after login

前端index.php里form表单:

Copy after login
Copy after login
...

请问问题出在哪,文件是有保存到相应的文件夹里的,就是路径没法返回到前端form表单里

parent:
该变量指的是包含当前分割窗口的父窗口。如果在一个窗口内有分割窗口,而在其中一个分割窗口中又包含着分割窗口,则第2层的分割窗口可以用parent变量引用包含它的父分割窗口。

点击submit时页面被跳转,parent无效。

建议你使用异步。

表单已提交,页面刷新了,所以php文件里输出的js没用,建议做ajax上传,返回文件存储路劲,然后提交表单。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template