phpshell-execcp

Copy multiple files using if(isset($_GET


I'm trying to copy 2 files at once, a video file and an image file with the same name using if(isset($_GET['video'])) but I can't seem to get it right. I can copy the video but my attempt to copy the thumbnail image fail.

From the other PHP file I'm sending this for example videos.php?video=data/videos/16440311.mp4 To the receiver to copy both video and thumbnail image to another location.

if(isset($_GET['video']))
    $file = $_GET['video'];
    $thumb = basename($file, '.mp4');

{
    shell_exec("sudo cp ".urldecode($_GET['video'])." /var/www/html/led/autoplayv/");
    shell_exec("sudo cp ".urldecode($thumb).".jpg /var/www/html/led/autoplayv/");
    
}

But when I check the folder all I see is the video.


Solution

  • You are closer than you think). The image is not copied due to the fact that you do not pass the full path, but only the name:

    $file = 'data/videos/16440311.mp4';
    $thumb = basename($file, '.mp4'); // <-- This function will only return the filename, because of this the error
    

    If the picture is on the same path as the video, then you will have to do this:

       $thumb = str_replace('.mp4','.jpg',$file);// <-- This return full path data/videos/16440311.jpg
       shell_exec("sudo cp {$thumb} /var/www/html/led/autoplayv/");