Answer the question
In order to leave comments, you need to log in
How to feed image models in yii without a form?
Good afternoon,
I ran into a problem when parsing a list of data. The data contains links to image folders that must be loaded along with the data.
If you use the following construction:
@file_put_contents($pathLocale, file_get_contents($pathRemote));
$model->save()
loaded in the same way as it happens when the element is loaded through the form. Because the behavior for the main picture and the behavior for additional ones are being worked out. images (in particular, the afterSave() behavior method ). ''''
$this->uploadImages($images, $bust);
// My::printArr($_FILES);
// My::printArr($_POST);
if(!$model) {
$model = new Objects();
}
$model->setAttributes($excel, true);
if(!$model->save())
echo 'Ошибка сохранения '. My::printArr($model->printErrors());
}
private function uploadImages($images, $path) {
// foreach ((array)$_POST["prev_image_ids"] as $md5) {
if(!$images){
return;
}
foreach ($images as $image) {
$md5 = md5(microtime()); // basename($md5);
$imagePath = $path . '/' . $image;
$tmpName = "/tmp/{$md5}"; //"./already-uploaded/{$md5}";
// $img = 'http://static2.t-ru.org/logo/logo.gif';
$getInfo = getimagesize($imagePath);
// My::printArr($getInfo);
// header('Content-type: ' . $getInfo['mime']);
// readfile($img);
// die();
$_FILES['Objects']["pictures"][] = [
"tmp_name" => $imagePath, // $tmpName,
"size" => filesize($imagePath), // $tmpName
"type" => $getInfo['mime'], // image/png
"name" => $image, // Screenshot_20161117_141028.png
"error" => UPLOAD_ERR_OK,
];
}
$_FILES['Objects']["photo"] = $_FILES['Objects']["pictures"][0];
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question