简体   繁体   中英

can't upload file on server

I am trying use this example http://www.sajithmr.me/jrecorder/example2.html for recording audio and send it to my localhost server, but I have issue here. My code describe below

<script>

   $.jRecorder(

     { 
        host : 'http://localhost/Jrec/html/acceptfile.php?filename=hello.wav',  
        callback_started_recording:     function(){callback_started(); },
        callback_stopped_recording:     function(){callback_stopped(); },
        callback_activityLevel:          function(level){callback_activityLevel(level); },
        callback_activityTime:     function(time){callback_activityTime(time); },
        callback_finished_sending:     function(time){ callback_finished_sending() },
        swf_path : 'jRecorder.swf',

     }
   );
   </script>

this my acceptfile.php

      if(!isset($_REQUEST['filename']))
   {
     exit('No file');
   }

   $upload_path = dirname(__FILE__). '/';

   $filename = $_REQUEST['filename'];

   $fp = fopen($upload_path."/".$filename.".wav", "wb");

   fwrite($fp, file_get_contents('php://input'));

   fclose($fp);

   exit('done');

whalt should I do with $upload_path = dirname( FILE ). '/;?
when I press send data button the file doesn't upload into following directory ("files"). What is the problem here, Any help will be apriciated

it works like Shikiryu and seth flowers said. But remember to remove .wav from filename because it adds the extension .wav here: $fp = fopen($upload_path."/".$filename.".wav", "wb");

Also note the 2 forward-slashes "/" concatenated in the filepath variable $fp .

  • 1st from $upload_path
  • 2nd from $fp

This assumes you will create a folder in your directory to store the sound file.

$fp = fopen($upload_path."NAME_OF_FOLDER/".$filename.".wav", "wb");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM