[php: ClassUploadPhp] 画像アップロードライブラリ ClassUploadPhp note. #php
/*
## refs
https://github.com/verot/class.upload.php/blob/master/README.md
*/
use upload;
// maybe cake controller method
if($this->request->is('post')){
try {
$Upload = new upload($_FILES['image']);
if ($Upload->uploaded) {
$Upload->file_new_name_body = $id;
$Upload->image_resize = true;
$Upload->image_x = 600;
$Upload->image_ratio_y = true;
$Upload->process("/var/www/html/img/");
$ext = $Upload->file_src_name_ext;
if ($Upload->processed) {
$fullpath = "http://hogehoge/assets/img/".$filename.$ext;
$this->View->setVars('message','アップロードに成功しました。');
$this->View->setVars('preview',$fullpath);
$Upload->clean();
} else {
$this->View->setVars('message','エラーが発生しました...' . $Upload->error);
}
}
} catch (\Exception $e) {
$this->Error->shutdown($e);
}
}
<form enctype="multipart/form-data" method="post" action="upload.php">
<input type="file" size="32" name="image" value="">
<input type="submit" name="Submit" value="upload">
</form>
"require": {
"verot/class.upload.php": "dev-master"
}