• Resolved semiarte

    (@semiarte)


    Hi
    I want to read a specific file from my functions.php to test imagick php extension. But http request fails.

    Any idea. Thank you

    function convertFile() {
        if (extension_loaded('imagick')) {
            echo "Imagick extension loaded!";
            
        } else {
            echo "No imagick extension loaded!";
        } 
    
        $upload_dir = wp_upload_dir();
        $image_file_location = $upload_dir['url'] . '/Conexion-VPN-con-doble-autenticacion.pdf';
        if ($image_file_location !== false) {
            $imagick = new Imagick();
            $imagick->readImage($image_file_location); // HTTP request fails
        } else {
            echo 'Can′t load image from url'; 
        }
    }
    add_action('wp_head', 'convertFile');
    • This topic was modified 3 years, 11 months ago by semiarte.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator bcworkz

    (@bcworkz)

    I believe that method wants a server file system path, not a HTTP URL. Try something like
    $image_file_location = $upload_dir['path'] . '/Conexion-VPN-con-doble-autenticacion.pdf';

    Thread Starter semiarte

    (@semiarte)

    Hi. Server file system returns not authorized message

    Moderator bcworkz

    (@bcworkz)

    Double check that the value assigned to $image_file_location is the correct path. If it is, the file’s permissions are probably incorrect. The user or group PHP runs under needs to have read permission. This is usually not your user, but the one specified in httpd.conf (Apache server configuration). Permissions can be set via FTP or your hosting file manager.

    Thread Starter semiarte

    (@semiarte)

    I got it. To fix ‘ImagickException: not authorized’ in extension policy.xml you have to update this line:

    <policy domain="coder" rights="none" pattern="PDF" />

    To read and write pdf files:

    <policy domain="coder" rights="read|write" pattern="PDF" />

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Imagick::readimage(): HTTP request failed’ is closed to new replies.