简体   繁体   中英

copy processed mp3 files from one directory to another directory in php

I am working on a php code as shown below which is converting mp4 files into mp3 using ffmpeg . After conversion, everything goes into outgoing_folder .

<?php
const DS = '/';
$src_dir    = 'incoming_folder';   /* Place where mp4 file is present */

$destination = 'outgoing_folder';  /* Place where mp3 files come after conversion from mp4 */

$mp3_processed = 'podcast_mp3_processed'; /* Place where I also want mp3 files */

foreach ($mp4_files as $f)
{

    $parts = pathinfo($f);
    switch ($parts['extension'])
    {
        case 'mp4' :
            $filePath = $src_dir . DS . $f;
            system('ffmpeg -i ' . $filePath . ' -map 0:2 -ac 1 ' . $destination . DS . $parts['filename'] . '.mp3', $result);    /** Place where mp3 file goes after conversion from mp4 **/

            if ($result)
            {
                // Do something with result if you want
                // log for example
            }
            break;

        case 'mp3' :
            // copy($f, $destination. DS . $parts['filename']. '.' . $parts['extension']);
            copy($f, $destination . DS . $parts['filename'] . '.mp3');
            copy('outgoing_folder', 'podcast_mp3_processed');   /* Line #A */
            break;
    }
}
?>

Problem Statement:

I am wondering what changes I need to make in the php code above so that when all mp4 files have been converted to mp3 then it should also go to podcast_mp3_processed folder.

At this moment it is going outgoing_folder but I also want it to go to podcast_mp3_processed folder. I tried with the code at Line#A but it doesn't seem to work.

You are trying to copy a directory and the PHP copy function only handles files. Ref: https://www.php.net/manual/en/function.copy.php

You can change your Line #A by duplicating the line before it and simply changing the directory variable $destination with $mp3_processed .

copy($f, $mp3_processed. DS . $parts['filename'] . '.mp3');

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