<?php
$cmd = 'yarn build';
exec( 'cd ' . __DIR__ . ' && ' . $cmd, $out, $res);
if ($res === 0) echo '<h1>OK!</h1>';
else echo '<h1>Fail!</h1>';
if(substr($source_file, 0, 7) == 'http://' || substr($source_file, 0, 8) == 'https://')
public function download_image($filename)
{
// Заливаем только есть такой файл есть в базе
$this->db->query('SELECT 1 FROM __images WHERE filename=? LIMIT 1', $filename);
if(!$this->db->result())
return false;
// Имя оригинального файла
$basename = explode('&', pathinfo($filename, PATHINFO_BASENAME));
$uploaded_file = array_shift($basename);
$base = urldecode(pathinfo($uploaded_file, PATHINFO_FILENAME));
$ext = pathinfo($uploaded_file, PATHINFO_EXTENSION);
// Если такой файл существует, нужно придумать другое название
$new_name = urldecode($uploaded_file);
while(file_exists($this->config->root_dir.$this->config->original_images_dir.$new_name))
{
$new_base = pathinfo($new_name, PATHINFO_FILENAME);
if(preg_match('/_([0-9]+)$/', $new_base, $parts))
$new_name = $base.'_'.($parts[1]+1).'.'.$ext;
else
$new_name = $base.'_1.'.$ext;
}
$this->db->query('UPDATE __images SET filename=? WHERE filename=?', $new_name, $filename);
// Перед долгим копированием займем это имя
fclose(fopen($this->config->root_dir.$this->config->original_images_dir.$new_name, 'w'));
copy($filename, $this->config->root_dir.$this->config->original_images_dir.$new_name);
return $new_name;
}
// Перед долгим копированием займем это имя
fclose(fopen($this->config->root_dir.$this->config->original_images_dir.$new_name, 'w'));
if(substr($filename, 0, 8) == 'https://'){
$t=$this->getSslPage($filename);
file_put_contents($this->config->root_dir.$this->config->original_images_dir.$new_name, $t);
}else
copy($filename, $this->config->root_dir.$this->config->original_images_dir.$new_name);
private function getSslPage($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_REFERER, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}