简体   繁体   中英

how to check if .exe file exists in php

Hi there is there any way to check if .exe file exists on a given path or not. I have installation of ImageMagic . I have a path of convert.exe of Image Magic. I need to check that in given path the convert.exe exists or not. I have implemented

$settingFileContent = file_get_contents($settingFilePath);
       // print_r($settingFileContent);
        $allPaths = unserialize(stripslashes($settingFileContent));

if (isset($allPaths['IMAGE_CONVERT_EXE'])) {
                //cho $allPaths['IMAGE_CONVERT_EXE'];
                if (file_exists($allPaths['IMAGE_CONVERT_EXE'])) {
                    $analysisResultObj->level = ENUM_SUCCESS;
                } else {
                    $analysisResultObj->level = ENUM_ERROR;
                    $analysisResultObj->infoText = "Image Magic convert.ext has wrong path";   
                 Logger::getLogger('Application')->error('Image Magic convert.ext has wrong path');
                }
            }

I can change the value of $allPaths['IMAGE_CONVERT_EXE'] in file. When I change to wrong value even in that condition it returns true.

Based on the documentation comment specifically about PHP on Windows I'm guessing (and let's be clear: everything in PHP is a guess) try this:

$file = 'd:/somfolder/imagemagic/convert.ext'
if(file_exists($file)) {
    // should be false
}

Based on your actual code have you tried:

$file = $allPaths['IMAGE_CONVERT_EXE'];
if(file_exists($file)) {
    // should be false
}

Looking at the documentation someone commented about having this same problem on Windows and being unable to return the correct result when concatenating string values. While you are not concatenating string values together its at least worth a shot to make sure there isn't something else strange going on.

To me it sounds like you're trying to get wether or not the Imagemagick extension exists. PHP provides ways for doing just that thus eliminating your extrapolated and insane approach all together.

<?php    
    echo extension_loaded('imagick');
?>

Additionally, you can get an idea of your installed extensions via

<?php 
    print_r(get_loaded_extensions()); 
?>

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