So I wrote a bash script that takes in 2 parameters.
- Local filename
- File name to be stored in the object store.
I want a php script to be able to run this and so I wrote something like this:
<?php
$output = shell_exec("./uploadFile.sh 'confirmation.txt' 'test_conf_script'");
echo $output;
?>
This is obviously hardcoded but worked fine using the command:
php -f test.php
.
Now I wanted my web application to be able to upload a file to the object store using the same bash script and so I modified my php script like this:
<?php
$target_dir = "./upload/";
$name = (string)$_POST['name'];
$file_name = (string)basename($_FILES["file"]["name"]);
$target_file = $target_dir . basename($_FILES["file"]["name"]);
$file_type = $_FILES["file"]["type"];
$file_size = $_FILES["file"]["size"];
if(move_uploaded_file($_FILES["file"]["tmp_name"], $target_file)){
echo "Upload\n";
}
else{
echo "couldn't upload!";
}
$output = shell_exec("./uploadFile.sh '$file_name' '$name'");
echo "./uploadFile.sh '$file_name' '$name'";
?>
My frontend provides the script with the file and I do see my file locally.
However the uploading to the object store using shell_exec doesnt work..
It seems bizzare since its exactly the same as the test.php file and although that works from the terminal, when my frontend triggers this php script it doesnt work.