1

I am making an application that requires a .sh script to be run on a file that has been newly uploaded on my XAMPP server (directory :/opt/lampp/htdocs/audio_server/uploads) which just simply moves it from one directory to another. The following is my PHP code to call the file:

    <?php
     print_r($_FILES);
     $target_path = "uploads/";

     $target_path = $target_path . basename( $_FILES['audio_name']                                          ['name']); 

      if(move_uploaded_file($_FILES['audio_name']['tmp_name'], $target_path))
     {
         echo "The file ".  basename( $_FILES['audio_name']['name'])." has been uploaded";
         chmod ("uploads/".basename( $_FILES['audio_name']['name']), 0777);
     }
     else
     {
         echo "There was an error uploading the file, please try again!";
         echo "filename: " .  basename( $_FILES['audio_name']['name']);
         echo "target_path: " .$target_path;
     }
     echo shell_exec("/opt/lampp/htdocs/audio_server/uploads/dirChangeScript.sh 2>&1");

     ?>

and my dirChangeScript.sh file is as follows:

    latest_file=$(ls -t | head -n 1)
    cp -p "$latest_file" /opt/lampp/htdocs/audio_server/converted

Executing the above script i get the error "omitted directory 'uploads' ".

The problem as weird as it may sound is that whenever the dirChangeScript script runs from the PHP file no effect is observed i.e. the latest file is not copied to the specified folder.

But when I execute the script through the terminal the proper file(latest one) is copied to the target directory.

Also i tried the following statement also:

    cp -r "$latest_file" /opt/lampp/htdocs/audio_server/converted

But in this case the whole uploads directory along with all of its files is copied inside the converted folder.

0

You must log in to answer this question.

Browse other questions tagged .