PHP: imagemagick creates an empty image with conversion

I have a script that should take an image and convert it to .jpg. This is the code that does this:

$uploadDir = $_SERVER['DOCUMENT_ROOT'] . "/blogimages/";
$tempFile = ereg_replace("'", "_", basename($_FILES['newsImg']['name']));
$uploadFile = $uploadDir . $tempFile;
move_uploaded_file($_FILES['newsImg']['tmp_name'], $uploadFile);
$newPic = $uploadDir . $blogID . ".jpg";
if(file_exists($newPic)){
unlink($newPic);
}
$convertString = "$IM -strip $uploadFile $newPic";
echo "<!-- $convertString -->";
exec($convertString);

as you can see, I put the last line in the HTML comment so that I can see what is running. It happens that the converted image is created, but it is a 0-byte image. Therefore, data is not written to the file. Just to make sure that the converter really works as usual, I have to copy and paste the conversion line from the html comment to the command line, and it works fine. There seems to be problems in PHP exec. Any thoughts on why this might be?

+3
source share
2

, , , ? Imagemagick .

, , , , , .

+2

$_FILES['newsImg']['name'] , , move_uploaded_file(...) .

+1

Source: https://habr.com/ru/post/1779878/


All Articles