Saturday, October 17, 2015

Sorting multidimensional array

//Input
$files = Array
(
    

    [0] => Array
        (
            [filename] => 1.mp4
            [modified] => 0.00
        )

    [1] => Array
        (
            [filename] => video2
            [modified] => 1.00
        )

    [2] => Array
        (
            [filename] => video1
            [modified] => 2.00
        )

)

usort($files, array('UsersController','date_compare'));

$files is your multidimensional array
UsersController is your class name
date_compare is function

function date_compare($a, $b){
        $t1 = strtotime($a['modified']);
        $t2 = strtotime($b['modified']);
        return $t2 - $t1;
    }

Output
Array
(
    

    [0] => Array
        (
            [filename] => video1

            [modified] => 2.00
        )

    [1] => Array
        (
            [filename] => video2
            [modified] => 1.00
        )

    [2] => Array
        (
            [filename] => 1.mp4
            [modified] => 0.00
        )

)
Read More »

Friday, October 16, 2015

Upload BY FTP


if(!empty($submitne))
{
$form_data = $fwRequest->getParam('ne_days', array());
$tblne_days = new Fw_Db_Table('ne_days');

$ext = strtolower(array_pop(explode('.',$_FILES['video']['name'])));

$video_ext = array("flv");

//if(in_array($ext,$video_ext))
//{
$video_name = time()."_".$_FILES['video']['name'];
$destination=BASE_DIR ."upload/video/".$video_name;


$ch = curl_init();
$file = $_FILES['video']['tmp_name'];
$fp = fopen($file, 'r');
curl_setopt($ch, CURLOPT_URL, 'ftp://whamcmsc:ejV61I77rv@whamcms.com/public_html/bvps/upload/video/'.$video_name);
curl_setopt($ch, CURLOPT_UPLOAD, 1);
curl_setopt($ch, CURLOPT_INFILE, $fp);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($file));
curl_exec ($ch);
$error_no = curl_errno($ch);
curl_close ($ch);
if ($error_no == 0) {
$screenshotname = str_replace($ext,'jpg',$video_name);
captureImageFromVideo($screenshotname,$video_name);

if(!in_array($ext,$video_ext))
{
$flvname = str_replace($ext,'flv',$video_name);
convertToflv($flvname,$video_name);
$form_data['video']=$flvname;
}
else
{
$form_data['video']=$video_name;
}


} else {
//echo $error_no;
die('Sorry, Video file not supported type.');
}


//}
}
Read More »