I have a script that uploads a file. It then creates a new folder and moves the uploaded file to that folder along with the another script.
After the file is moved, I need to run a second script that resides in the new folder. But I need the second script to use its path and NOT the path of where it is called/executed from. (the upload script)
This is how I have tried to execute the script from the upload script.
exec("php-cli uploads/".$dirname."/".$file_name."/generate_thumbs.php");
I have error reporting on but nothing is generated. Any ideas?
If you want to change working directory, use chdir()
before exec()
. You can pass either absolute or relative directory name. To execute PHP from PHP you can use include
instead of exec()
.
edit your upload script to:
<?php
// ... upload the file ...
// ,,open'' the target directory
chdir("uploads/$dirname/$file_name/");
// start the thumbs script
// this filename is relative to "uploads/$dirname/$file_name/"
include "generate_thumbs.php";
?>
What you should do is within your second script to use path to where the script is.
As found in the answer: Get absolute path of current script
From there you can write your script to operate from where it is as long as you can resolve where it is.