1

I have a PHP script which receives an upload and defers processing of that upload to a background script via shell_exec().

But the background script can't seem to access the temporary file of the upload.

Receiver script

$file_loc = $_FILES['file']['tmp_name'];
echo $file_loc.' exists = '.file_exists($file_loc);
shell_exec('php background.php -i='.$file_loc.' >report.txt &');

This outputs

{path to file} exists = 1

Background.php

$args = getopt('i:');
$file_loc = $args['i'];
echo $file_loc.' exists = '.file_exists($file_loc);

In result.txt I get

{path to file} exists =

i.e. doesn't exist. What do I need to do to allow the background script to access the tmp file location?

Mitya
  • 33,629
  • 9
  • 60
  • 107

1 Answers1

1

You should move the uploaded file to a new destination to process the file.

$destination = "FOLDER_NAME/".$_FILES['file']['tmp_name'];
$file_loc = $_FILES['file']['tmp_name'];
move_uploaded_file ( $file_loc, $destination )
echo $destination.' exists = '.file_exists($destination);
shell_exec('php background.php -i='.$destination.' >report.txt &');
Lithilion
  • 1,097
  • 2
  • 11
  • 26