This is the code I wrote which helps me upload an image from a html page(https://pastebin.com/hjDYrXs0 saved as index.html.php)
that I've hosted locally using wamp server :
$upload_dir = 'uploads'.DIRECTORY_SEPARATOR;
$allowed_types = array('jpg', 'png', 'jpeg', 'gif');
$maxsize = 2 * 1024 * 1024;
if(!empty(array_filter($_FILES['files']['name']))) {
foreach ($_FILES['files']['tmp_name'] as $key => $value) {
$file_tmpname = $_FILES['files']['tmp_name'][$key];
$file_name = $_FILES['files']['name'][$key];
$file_size = $_FILES['files']['size'][$key];
$file_ext = pathinfo($file_name, PATHINFO_EXTENSION);
$filepath = $upload_dir.$file_name;
if(in_array(strtolower($file_ext), $allowed_types)) {
if ($file_size > $maxsize)
echo "Error: File size is larger than the allowed limit.";
if(file_exists($filepath)) {
$filepath = $upload_dir.time().$file_name;
if( move_uploaded_file($file_tmpname, $filepath)) {
echo "{$file_name} successfully uploaded <br />";
..... other conditions (not uploaded and not selected)........
So basically I want to send the image I get from the uploaded php as an argument to the batch file like A:\WAMP\www\test\uploads\batscript.bat A:\WAMP\www\test\uploads\upload.jpg
It works if I execute it manually.
After going through other similar questions over here at stack like Run cmd bat file in PHP , How do you run a .bat file from PHP? , How to execute batch file via PHP?
I tried these things
echo system("cmd /c A:\WAMP\www\test\uploads\batscript.bat $file_name");
echo exec("A:\WAMP\www\test\uploads\batscript.bat $file_name");
Unfortunately it isn't working.... Any clues to what I could do to make it work ? ? ?