简体   繁体   中英

Executing Imagemagick's convert returning error code 1

[edit after answer of Bonzo] after the following code, I am getting this error :

Array
(
    [0] => magick: unable to create temporary file 'aboutproject1.pdf': Permission denied @ error/pdf.c/ReadPDFImage/476.
)

How can I permit cration of temporary file ? My current user is Daemon (apache/localhost)


[before edit] I am trying to issue a shell command from my PHP to convert a PDF to TIFF. But I am getting error code 1. Following is my code :

<?php 
if(isset($_FILES['file_up']["name"])){
//print_r($_FILES);
$file_name = $_FILES['file_up']["name"];
$tmp_name = $_FILES['file_up']["tmp_name"];

if(move_uploaded_file($tmp_name, "$file_name")){

$onlyname = pathinfo($_FILES['file_up']['name'], PATHINFO_FILENAME);
chmod("$file_name", 0777);

//Command that is returning error code 1
//Iam running it on aboutproject.pdf STATIC for novv.
exec("/usr/local/Cellar/imagemagick/7.0.7-1/bin/convert aboutproject1.pdf anyuf.tif", $output, $retval);    

//returning empty array
echo "output : ->"; print_r($output) ;
//returning error code 1
echo "RETURN : ->".$retval;

if ($retval == 0){

    echo "First command executed !";    
    }
}

exit();
}
?>

PLEASE, NOT FOLLOWING :

  • Given permission to folder and script residing aboutproject1.pdf
  • When I do man convert through same PHP script, it gives me the proper output(within the same folder)
  • When I run command through terminal it works
  • aboutproject1.pdf is created/uploaded by user daemon (apache)
  • I have tried running it as SUDO by manipulating sudoer and adding privilege for www-data (apache) to run the script and convert without requiring a password.

Please help me I am stuck.

Version 7 uses magick rather than convert. convert may still work but it depends on how Imagemagick was installed.

You could try this method of error reporting and see if you get any more information:

$array=array();
echo "<pre>";
exec("/usr/local/Cellar/imagemagick/7.0.7-1/bin/convert aboutproject1.pdf anyuf.tif 2>&1", $array); 
echo "<br>".print_r($array)."<br>"; 
echo "</pre>";

Instead of using this /usr/local/Cellar/imagemagick/7.0.7-1/bin/convert I would just use magick. If your version changes or the imagemagick location changes you will need to modify all your scripts.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM