The class Simple Image does not work normally when I call it through CRON. Works fine only when the call goes through the browser.

$image = new SimpleImage(); $image ->load($path); $format_avatar = explode(".", $path); $name_photo = md5(microtime() . $postId). '.' . $format_avatar[count($format_avatar) - 1]; $uploaddir_big = $_SERVER['DOCUMENT_ROOT'] . '/site.com/images/big/'; $image -> save($uploaddir_big . $name_photo) // = true, но файлов не обнаруженно 

Some functions from the class Simple Image

 function load($filename) { $image_info = getimagesize($filename); $this->image_type = $image_info[2]; if( $this->image_type == IMAGETYPE_JPEG ) { $this->image = imagecreatefromjpeg($filename); } elseif( $this->image_type == IMAGETYPE_GIF ) { $this->image = imagecreatefromgif($filename); } elseif( $this->image_type == IMAGETYPE_PNG ) { $this->image = imagecreatefrompng($filename); } } function save($filename, $image_type=IMAGETYPE_JPEG, $compression=75, $permissions=null) { if( $image_type == IMAGETYPE_JPEG ) { imagejpeg($this->image,$filename,$compression); return 'true'; } elseif( $image_type == IMAGETYPE_GIF ) { imagegif($this->image,$filename); return 'true'; } elseif( $image_type == IMAGETYPE_PNG ) { imagepng($this->image,$filename); return 'true'; } if( $permissions != null) { chmod($filename,$permissions); } 

}

Gives an error message

Warning: imagejpeg () [function.imagejpeg]: Unable to open 'site.com/images/big/dfa47b99317704b23660e09de5604dd4.jpg' for writing: No such file or directory .php

  • What is the value: $ uploaddir_big. $ name_photo)? - ReinRaus
  • /var/chroot/home/content/90/10541990/html/site.com/images/big/name.png - Zow
  • 2
    There is no right to write to the directory, as the error text says. - ReinRaus
  • one
    Assign directories permissions 777 and check again). As @ReinRaus said, the crown may not have rights to write to this directory. And the web server has it. - zenith
  • one
    $uploaddir_big = $_SERVER['DOCUMENT_ROOT'] cron doesn't know anything about this. somehow differently specify the site directory. - zb '

2 answers 2

what you run through the web works relative to the root of the site, cron works relative to the file system, perhaps because of this problem - try using absolute file system paths everywhere and not server variables

    When working with crown, I always use this code:

     if (in_array(strtolower(basename($_SERVER['SCRIPT_NAME'])),Array('php','php.exe'))) { $mod_path=dirname($_SERVER['PATH_INFO']); // Исполняемый файл }else{ $mod_path=dirname($_SERVER['SCRIPT_NAME']); } // Переход в каталог скрипта if ($mod_path!=getcwd()) @chdir($mod_path); 

    Inserted at the beginning of the script.