echo var_dump ($_POST);
echo var_dump ($_FILES);
$contentUser = new ContentsController();
//echo $_POST['title'];
if($this->request->data(['localId']) == ''){
$localId = null;
}else{
$localId= $this->request->data(['localId']);
}
$dir = null;
// $title = $_POST['title'];
$title = $this->request->data(['title']);
//$title = $_FILES["title"];
//echo $title;
$category = $this->request->data(['category']);
$summary = $this->request->data(['summary']);
$videoUrl = $this->request->data(['video']);
$description = $this->request->data(['description']);
$id_content=$contentUser->add($localId);
$video = $this->Videos->newEntity();
$video->title = $title;
$video->summary = $summary;
$video->body = $description;
$video->category_id = (int)$category;
$video->video=videoUrl
$video->content_id = $id_content;
// function uploadImageFile() { // Note: GD library is required for this function
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$iWidth = $iHeight = 300; // desired image result dimensions
$iJpgQuality = 90;
if (isset($_FILES['image_file'])) {
$Response = 'si';
$originalPhoto = $_FILES['image_file'];
// if no errors and size less than 250kb
if (! $_FILES['image_file']['error'] && $_FILES['image_file']['size'] < 250 * 1024) {
if (is_uploaded_file($_FILES['image_file']['tmp_name'])) {
// new unique filename
$rand = range(0000, 9999);
shuffle($rand);
foreach ($rand as $val) {
$code = $val;
}
$time = time();
$dir = $time.''.$code;
mkdir("../webroot/upload/videos/photo/".$dir, 0777,true);
$sTempFileName = '../webroot/upload/videos/photo/'.$dir.'/'.$time;
//$sTempFileNameOriginal = '../webroot/upload/videos/photo/'.$dir.'/'.$time;
// $video->photo = $time;
// $video->photo_dir = $dir;
// move uploaded file into cache folder
move_uploaded_file($_FILES['image_file']['tmp_name'], $sTempFileName);
// change file permission to 644
@chmod($sTempFileName, 0644);
if (file_exists($sTempFileName) && filesize($sTempFileName) > 0) {
$aSize = getimagesize($sTempFileName); // try to obtain image info
if (!$aSize) {
@unlink($sTempFileName);
return;
}
// check for image type
switch($aSize[2]) {
case IMAGETYPE_JPEG:
$sExt = '.jpg';
// create a new image from file
$vImg = @imagecreatefromjpeg($sTempFileName);
break;
case IMAGETYPE_PNG:
$sExt = '.png';
// create a new image from file
$vImg = @imagecreatefrompng($sTempFileName);
break;
default:
@unlink($sTempFileName);
return;
}
// create a new true color image
$vDstImg = @imagecreatetruecolor( $iWidth, $iHeight );
// copy and resize part of an image with resampling
imagecopyresampled($vDstImg, $vImg, 0, 0, (int)$this->request->data(['x1']), (int)$this->request->data(['y1']), $iWidth, $iHeight, (int)$this->request->data(['w']), (int)$this->request->data(['h']));
// define a result image filename
$sResultFileName = $sTempFileName . $sExt;
// output image to file
imagejpeg($vDstImg, $sResultFileName, $iJpgQuality);
@unlink($sTempFileName);
return $sResultFileName;
}
}
}
}
}
// }
// $sImage = uploadImageFile();
if($this->Videos->save($video)){
}