Jump to content
brizey882

PHP exec with variables

Recommended Posts

I'm having a bit of trouble with my code the first shell_exec works ($output = shell_exec("sudo alpr -c us $uploadfile") ;) but the 2nd (echo exec("exiftool -r -if '$gpsdatetime' -fileOrder gpsdatetime -p /var/www/html/uploads/intel.flt -d current $uploadfile > $uploadfile.php") ;) fails

 

<?php

$uploaddir = '/var/www/html/uploads/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

echo "<p>";

if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
  echo "Processed \n";
} else {
   echo "Upload failed";
}
 echo "The file ".  basename( $_FILES['userfile']['name']).
    " has been uploaded";

$output = shell_exec("sudo alpr -c us $uploadfile");
echo "<pre>$output</pre>";
echo exec("exiftool -r -if '$gpsdatetime' -fileOrder gpsdatetime -p /var/www/html/uploads/intel.flt -d current $uploadfile > $uploadfile.php");

?>

Edited by requinix
[code] tags go around code, not around your entire post

Share this post


Link to post
Share on other sites

php variables do not parse surrounded by single quotes

 

escape the directory/file paths with quotes

Share this post


Link to post
Share on other sites

Without any additional arguments to the exeftool app and some redirect output files (using just for testing purposes) everything works fine to me.

Here is an example using different php command-line apps (exec, eval and shell_exec).

Try to set also an absolute path to exiftool. 

<?php

$uploaddir = '/var/www/html/public_html/lxc/uploads/';

$uploadfile = $uploaddir . basename($_FILES['fileToUpload']['name']);

if (move_uploaded_file($_FILES['fileToUpload']['tmp_name'], $uploadfile)) {

//echo exec('/usr/local/bin/exiftool "'.$uploadfile.'"'); // Megapixels : 0.345

//eval('$array=' . `/usr/local/bin/exiftool -php -q $uploadfile`);

//print_r($array);

echo shell_exec('/usr/local/bin/exiftool "'.$uploadfile.'"');

} else {
   echo "Upload failed";
}

Outputs:

 

 

 

 

ExifTool Version Number : 9.97 File Name : 166688_1813367933281_1212517464_2171202_461168_n.jpg Directory : /var/www/html/public_html/lxc/uploads File Size : 96 kB File Modification Date/Time : 2015:06:13 09:47:56-04:00 File Access Date/Time : 2015:06:13 09:47:56-04:00 File Inode Change Date/Time : 2015:06:13 09:47:56-04:00 File Permissions : rw-r--r-- File Type : JPEG File Type Extension : jpg MIME Type : image/jpeg JFIF Version : 1.01 Resolution Unit : inches X Resolution : 72 Y Resolution : 72 Profile CMM Type : Profile Version : 2.0.0 Profile Class : Display Device Profile Color Space Data : RGB Profile Connection Space : XYZ Profile Date Time : 2009:03:27 21:36:31 Profile File Signature : acsp Primary Platform : Unknown () CMM Flags : Not Embedded, Independent Device Manufacturer : Device Model : Device Attributes : Reflective, Glossy, Positive, Color Rendering Intent : Perceptual Connection Space Illuminant : 0.9642 1 0.82491 Profile Creator : Profile ID : 29f83ddeaff255ae7842fae4ca83390d Profile Description : sRGB IEC61966-2-1 black scaled Blue Matrix Column : 0.14307 0.06061 0.7141 Blue Tone Reproduction Curve : (Binary data 2060 bytes, use -b option to extract) Device Model Desc : IEC 61966-2-1 Default RGB Colour Space - sRGB Green Matrix Column : 0.38515 0.71687 0.09708 Green Tone Reproduction Curve : (Binary data 2060 bytes, use -b option to extract) Luminance : 0 80 0 Measurement Observer : CIE 1931 Measurement Backing : 0 0 0 Measurement Geometry : Unknown Measurement Flare : 0% Measurement Illuminant : D65 Media Black Point : 0.01205 0.0125 0.01031 Red Matrix Column : 0.43607 0.22249 0.01392 Red Tone Reproduction Curve : (Binary data 2060 bytes, use -b option to extract) Technology : Cathode Ray Tube Display Viewing Cond Desc : Reference Viewing Condition in IEC 61966-2-1 Media White Point : 0.9642 1 0.82491 Profile Copyright : Copyright International Color Consortium, 2009 Chromatic Adaptation : 1.04791 0.02293 -0.0502 0.0296 0.99046 -0.01707 -0.00925 0.01506 0.75179 Image Width : 720 Image Height : 479 Encoding Process : Baseline DCT, Huffman coding Bits Per Sample : 8 Color Components : 3 Y Cb Cr Sub Sampling : YCbCr4:2:0 (2 2) Image Size : 720x479 Megapixels : 0.345

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.