function upload()
{
    $path = "./uploads/";
    //设置图片上传路径
    $up = new FileUpload($path);
    //创建文件上传类对象
    if ($up->upload('pic')) {
        //上传图片
        $filename = $up->getFileName();
        //获取上传后的图片名
        $img = new Image($path);
        //创建图像处理类对象
        $img->thumb($filename, 300, 300, "");
        //将上传的图片都缩放至在300X300以内
        $img->thumb($filename, 80, 80, "icon_");
        //缩放一个80x80的图标,使用icon_作前缀
        $img->watermark($filename, "logo.gif", 5, "");
        //为上传的图片加上图片水印
        return array(true, $filename);
        //如果成功返回成功状态和图片名称
    } else {
        return array(false, $up->getErrorMsg());
        //如果失败返回失败状态和错误消息
    }
}
Пример #2
0
 public function preform()
 {
     $uploadFile = new FileUpload();
     $uploadFile->set("maxsize", 2000000);
     $uploadFile->set("allowtype", array("gif", "png", "jpg", "jpeg"));
     $uploadFile->set("israndname", true);
     if ($this->params['safe']['type'] == "addArticle") {
         $path = "../uploadfile/article/" . $this->params['safe']['fenlei_id'] . "/";
         $uploadFile->set("path", $path);
         if ($uploadFile->upload('fm_img')) {
             $data = array('uid' => 1, 'title' => $this->params['safe']['title'], 'contents' => $this->params['safe']['contents'], 'fenlei_id' => $this->params['safe']['fenlei_id'], 'fm_img' => $path . $uploadFile->getFileName(), 'time' => time());
             $DaoArticle = new DaoArticle();
             $DaoArticle->insertArticle($data);
         } else {
             //获取上传失败以后的错误提示
             throw new Exception('error_file_upload', $uploadFile->getErrorMsg());
         }
     } elseif ($this->params['safe']['type'] == "addUser") {
         $path = "../uploadfile/user_img/" . $this->params['safe']['user_name'] . "/";
         $uploadFile->set("path", $path);
         if ($uploadFile->upload('user_img')) {
             $data = array('user_name' => $this->params['safe']['user_name'], 'user_nickname' => $this->params['safe']['user_nickname'], 'user_password' => md5($this->params['safe']['password']), 'user_qm' => "这家伙还没写签名呢!", 'user_img' => $path . $uploadFile->getFileName(), 'user_inTime' => time());
             $DaoUser = new DaoUser();
             $DaoUser->addUser($data);
         } else {
             //获取上传失败以后的错误提示
             throw new Exception('error_file_upload', $uploadFile->getErrorMsg());
         }
     } elseif ($this->params['safe']['type'] == "addfenlei") {
         $path = "../uploadfile/Fenlei/";
         $uploadFile->set("path", $path);
         if ($uploadFile->upload('fenlei_img')) {
             $data = array('name' => $this->params['safe']['name'], 'time' => time(), 'fenlei_img' => $path . $uploadFile->getFileName());
             $DaoFenlei = new DaoFenlei();
             $DaoFenlei->addFenlei($data);
         }
     }
 }
Пример #3
0
 public function actionUpload()
 {
     include __DIR__ . "./../uploader/Uploader.php";
     $upload_dir = \Yii::$app->getModule("file")->getStorageDir();
     $uploader = new \FileUpload('uploadfile');
     $fileModel = new File();
     $realName = $_GET["uploadfile"];
     // Handle the upload
     $isUplaoded = $uploader->handleUpload($upload_dir);
     $result = false;
     $errorMsg = '';
     if ($isUplaoded) {
         $fileModel = new File();
         $fileModel->setAttribute("real_name", $realName);
         $fileModel->setAttribute("name_on_server", $uploader->getSavedFileName());
         $fileModel->setAttribute("size", $uploader->getFileSize());
         if (!$fileModel->save()) {
             $uploader->rollBack();
             $errorMsg = "Entity save error";
         } else {
             if (!empty($_GET["relateTo"])) {
                 if (!$fileModel->linkWith($_GET["relateTo"])) {
                     $uploader->rollBack();
                     $fileModel->delete();
                     $errorMsg = "Entity link error";
                 } else {
                     $result = true;
                 }
             } else {
                 $result = true;
             }
         }
     } else {
         $errorMsg = $uploader->getErrorMsg();
     }
     if ($result) {
         echo json_encode(array('success' => true));
     } else {
         exit(json_encode(['success' => false, 'msg' => $errorMsg]));
     }
 }
Пример #4
0
        require '/opt/nginx/html/vendor/upload.php';
        $upload_directory = '/opt/nginx/html/public/uploads/subs';
        $allowed_extensions = array('srt');
        $max_size = 1048576;
        $uploader = new FileUpload('file');
        $ext = $uploader->getExtension();
        if (empty($ext)) {
            $response = Response::json(array('result' => false, 'location' => false, 'error' => 'Invalid file type.'));
            $response->header('Content-Type', 'application/json');
            return $response;
        }
        $filename = uniqid(uniqid(), true) . '.' . $ext;
        $uploader->newFileName = $filename;
        $uploader->sizeLimit = $max_size;
        $result = $uploader->handleUpload($upload_directory, $allowed_extensions);
        $errors = $uploader->getErrorMsg();
        if (!empty($errors)) {
            $response = Response::json(array('result' => false, 'location' => false, 'error' => $uploader->getErrorMsg()));
            $response->header('Content-Type', 'application/json');
            return $response;
        }
        $response = Response::json(array('result' => true, 'type' => 'subs_file', 'data' => URL::to('/uploads/subs') . '/' . $filename));
        $response->header('Content-Type', 'application/json');
        return $response;
    }
});
Route::get('upload', function () {
    if (Auth::guest()) {
    } else {
        return View::make('widgets.upload');
    }
Пример #5
0
}
if (isset($_POST['category']) && $_POST['category'] == 'code') {
    $up = new FileUpload();
    //设置属性(上传的位置, 大小, 类型, 名是是否要随机生成)
    $up->set("path", "../../upload/webstyle/public/" . $_POST['code_type']);
    $up->set("maxsize", 2000000);
    $up->set("allowtype", array("gif", "png", "jpg", "jpeg", 'css', 'js'));
    $up->set("israndname", false);
    //使用对象中的upload方法, 就可以上传文件, 方法需要传一个上传表单的名子 pic, 如果成功返回true, 失败返回false
    if ($up->upload("file")) {
        var_dump($up->getFileName());
        $file_path_code = '/manage/upload/webstyle/public/' . $_POST['code_type'] . '/' . $up->getFileName();
    } else {
        echo '<pre>';
        //获取上传失败以后的错误提示
        var_dump($up->getErrorMsg());
        echo '</pre>';
    }
    $db = new DB();
    $data['id'] = "";
    $data['title'] = $_POST['code_title'];
    //$data['content'] = $_POST['code_content'];
    $data['type'] = $_POST['code_type'];
    $data['file_path'] = $file_path_code;
    $data['is_public'] = 1;
    $db->insert('webstyle_code', $data);
}
if (isset($_POST['action']) && $_POST['action'] == 'tempSaveFile') {
    //生成文件
    $File = new FileUtil();
    $File->writetofile(BASE_PATH . 'views/templates/webstyle/temp/' . time() . '.js', $_POST['content']);
Пример #6
0
<?php

include_once "config.php";
require dirname(__FILE__) . '/Class/Uploader.php';
// Directory where we're storing uploaded images
// Remember to set correct permissions or it won't work
$upload_dir = IMAGEDEVICES;
$valid_extensions = array('gif', 'png', 'jpeg', 'jpg');
$uploader = new FileUpload('uploadfile');
// Handle the upload
$result = $uploader->handleUpload($upload_dir);
if (!$result) {
    exit(json_encode(array('success' => false, 'msg' => $uploader->getErrorMsg())));
}
echo json_encode(array('success' => true));
Пример #7
0
<?php

require "FileUpload.class.php";
$up = new FileUpload(array('isRandName' => true, 'allowType' => array('txt', 'doc', 'php', 'gif'), 'FilePath' => './uploads/', 'MAXSIZE' => 200000));
echo '<pre>';
if ($up->uploadFile('spic')) {
    print_r($up->getNewFileName());
} else {
    print_r($up->getErrorMsg());
}
echo '</pre>';
Пример #8
0
                 //手填路径
                 $ordername = '';
             } else {
                 //选择图片提交
                 $picstr = $picurlarr[count($picurlarr) - 1];
                 $picarr = explode('.', $picstr);
                 array_pop($picarr);
                 $ordername = implode('.', $picarr);
             }
         }
     }
     $up = new FileUpload(array('isRandName' => true, 'allowType' => array('swf'), 'FilePath' => $filepath, 'MAXSIZE' => 20 * 1024 * 1024, 'ordername' => $ordername));
     if ($up->uploadFile('flashpic')) {
         $_POST['adv']['flash']['url'] = '/uploadfiles/guanggao/' . $up->getNewFileName();
     } else {
         redirect($up->getErrorMsg(), '-1');
     }
 }
 //zhaoyanmin end
 $code = addslashes(serialize($_POST['adv']));
 !$varname && alert("广告标识符不能为空");
 if ($id) {
     $DreamCMS->db->query("UPDATE `#DC@__advertise` SET `varname` = '{$varname}',`title` = '{$title}',`style`='{$style}',`starttime` = '{$starttime}',`endtime` = '{$endtime}',`code` = '{$code}',`status` = '{$state}' WHERE `id` ='{$id}'");
 } else {
     $DreamCMS->db->query("INSERT INTO `#DC@__advertise`(`varname` , `title` ,`style`, `starttime` , `endtime` , `code` , `status` ) VALUES ('{$varname}','{$title}','{$style}','{$starttime}', '{$endtime}', '{$code}', '{$state}')");
     $id = $DreamCMS->db->insert_id;
 }
 $jsfile = "YWR2ZXJ0aXNl/{$style}-id-{$id}.js";
 $html = getadvhtml($style, stripslashes($code));
 $html = "/*\n{$varname}\n标签:<!--{DreamCMS:advertise name=\"{$varname}\"}-->\n*/\n" . documentwriteln($html);
 writefile(DCPATH . $jsfile, $html);
Пример #9
0
                            $id = $db->insert_id();
                            echo "<script>alert('视讯信息添加成功,请上传视讯文件?');location.href='../videoadd.php?task=uploadVideoFile&id={$id}';</script>";
                        } else {
                            print_r($up->getErrorMsg());
                            echo "<script>alert('视讯添加失败,是否重试?');location.href='../videoadd.php;</script>";
                        }
                    } else {
                        if (isset($_POST[task]) && "addVideoFile" == $_POST[task]) {
                            //文件保存目录路径
                            $save_path = '../../../video/file/';
                            //定义允许上传的文件扩展名
                            $ext_arr_file = array('swf', 'avi', 'asf', 'mid', 'wmv', 'wma', 'ra');
                            require "FileUpload.class.php";
                            $upFile = new FileUpload(array('isRandName' => true, 'allowType' => $ext_arr_file, 'FilePath' => $save_path, 'MAXSIZE' => 200485760));
                            if ($upFile->uploadFile('upfile')) {
                                //print_r($up->getNewFileName());
                                $fname = $upFile->getNewFileName();
                                $sql = "update video set video_path='../video/file/{$fname}' where id = {$_POST['id']}";
                                $db->query($sql);
                                echo "<script>if(confirm('视讯添加完成,是否继续添加?')){location.href='../videoadd.php';}else{location.href='../videolist.php';}</script>";
                            } else {
                                print_r($upFile->getErrorMsg());
                                echo "<script>alert('视讯添加失败,是否重试?');location.href='../videoadd.php';</script>";
                            }
                        }
                    }
                }
            }
        }
    }
}
Пример #10
0
<?php

require 'Uploader.php';
//try to get the directory from the request
$dir = htmlspecialchars($_GET["dir"]);
//if it is null
if ($dir === null || $dir === "") {
    echo json_encode(array('success' => false, 'msg' => $Upload->getErrorMsg()));
    return;
} else {
    if ($dir === "files") {
        $upload_dir = '././Content/files/';
        //$valid_extensions = array('adi', 'txt', 'cabrillo.txt', 'log', 'cbr');
    } else {
        echo json_encode(array('success' => false, 'msg' => $Upload->getErrorMsg()));
        return;
    }
}
$Upload = new FileUpload('uploadfile');
$ext = $Upload->getExtension();
// Get the extension of the uploaded file
$time = time();
$Upload->newFileName = $time . '.' . $ext;
//$result = $Upload->handleUpload($upload_dir, $valid_extensions);
$result = $Upload->handleUpload($upload_dir);
if (!$result) {
    echo json_encode(array('success' => false, 'msg' => $Upload->getErrorMsg()));
} else {
    echo json_encode(array('success' => true, 'file' => $Upload->getFileName(), 'timestamp' => $time));
}
Пример #11
0
if (isset($_POST[task]) && "LoginADCode" == $_POST[task]) {
    //文件保存目录URL
    $save_path = '../../images/ad/';
    //定义允许上传的文件扩展名
    $ext_arr = array('gif', 'jpg', 'png');
    require "../action/FileUpload.class.php";
    $up = new FileUpload(array('isRandName' => true, 'allowType' => $ext_arr, 'FilePath' => $save_path, 'MAXSIZE' => 1024 * 500));
    if ($up->uploadFile('adimage')) {
        $query = $db->query("select type_url,type_code from lm_comm_code where type_name='LoginAdCode' and id='{$_POST['adid']}'");
        $info = $db->fetch_array($query);
        $filename = "images/ad/" . $up->getNewFileName();
        $db->query("update lm_comm_code set type_code='{$filename}',type_url='{$_POST['type_url']}' where type_name='LoginAdCode' and id='{$_POST['adid']}'");
        unlink("../../" . $info[type_code]);
        echo "<script>alert('修改成功!');location.href='../loginad.php';</script>";
    } else {
        printf($up->getErrorMsg());
        $db->query("update lm_comm_code set type_url='{$_POST['type_url']}' where type_name='LoginAdCode' and id='{$_POST['adid']}'");
        echo "<script>alert('图片修改失败或者图片没有修改,广告其他信息修改成功!');location.href='../loginad.php';</script>";
    }
} else {
    if (isset($_POST[task]) && "ADCode" == $_POST[task]) {
        //文件保存目录URL
        $save_path = '../../images/ad/';
        //定义允许上传的文件扩展名
        $ext_arr = array('gif', 'jpg', 'png');
        require "../action/FileUpload.class.php";
        $up = new FileUpload(array('isRandName' => true, 'allowType' => $ext_arr, 'FilePath' => $save_path, 'MAXSIZE' => 1024 * 500));
        if ($up->uploadFile('adimage')) {
            $query = $db->query("select type_url,type_code from lm_comm_code where type_name='AdCode' and id='{$_POST['adid']}'");
            $info = $db->fetch_array($query);
            $filename = "images/ad/" . $up->getNewFileName();
Пример #12
0
 function upload_car($id = 0)
 {
     $this->load->library('FileUpload');
     $upload_dir = 'assets/uploads/cars/';
     $uploader = new FileUpload('uploadfile');
     // Handle the upload
     $result = $uploader->handleUpload($upload_dir);
     if (!$result) {
         exit(json_encode(array('success' => false, 'msg' => $uploader->getErrorMsg())));
     }
     $update = array('img_name' => $uploader->getFileName());
     $this->car_model->update(array('id' => $id), $update);
     echo json_encode(array('success' => true, 'fname' => $uploader->getFileName()));
     exit;
 }
Пример #13
0
 function upload($path = '')
 {
     $path = trim($path, '/');
     $folder = $this->BasePath . $path;
     if (!is_dir($folder)) {
         if (is_gb2312($path)) {
             $path = iconv('gb2312', 'utf-8', $path);
         }
         throw new Exception("文件夹 '{$path}' 不存在。");
     }
     if (!file_exists('fileupload.class.php')) {
         throw new Exception("没找到文件'fileupload.class.php, 无法上传文件。");
     }
     require_once 'fileupload.class.php';
     $up = new FileUpload();
     //设置属性(上传的位置, 大小, 类型, 名是是否要随机生成)
     $up->set("path", $folder);
     $up->set("maxsize", 8 * 1024 * 1024);
     if (empty($this->allowType) || $this->allowType == '*') {
         $up->set("allowtype", explode(',', $this->allType));
     } else {
         $up->set("allowtype", explode(',', $this->allowType));
     }
     $up->set("israndname", false);
     if (!$up->upload("file")) {
         $errors = $up->getErrorMsg();
         if (is_array($errors)) {
             $errors = implode("\n", $errors);
         }
         throw new Exception($errors);
     } else {
         $filenames = $up->getFileName();
         if (is_string($filenames)) {
             $filenames[] = $filenames;
         }
         foreach ($filenames as $key => $value) {
             $filename = iconv('utf-8', 'gb2312', $value);
             if (true === @rename($folder . '/' . $value, $folder . '/' . $filename)) {
                 $filenames[$key] = $filename;
             }
         }
     }
     return $up->getFileName();
 }
Пример #14
0
<?php

require_once 'logincheck.php';
require_once '../library/uploadfile.php';
require_once '../library/excel/reader.php';
$option = array('filepath' => '../upload', 'allowtype' => array('xls'), "maxsize" => "10000000", "israndname" => true);
$file = new FileUpload($option);
if (!$file->uploadFile("uploadfile")) {
    //获取要上传的文件,上传
    $message = $file->getErrorMsg();
} else {
    //插入到数据库中
    $xl = new Spreadsheet_Excel_Reader();
    $xl->setOutputEncoding('CP936');
    $xl->read($option["filepath"] . '/' . iconv("utf-8", "GBK", $file->getNewFileName()));
    $succeed = 0;
    $lost = 0;
    for ($i = 2; $i <= $xl->sheets[0]['numRows']; $i++) {
        $data['STU_NUM'] = str_replace(' ', '', iconv("gb2312", "utf-8", $xl->sheets[0]['cells'][$i][1]));
        $data['STU_NAME'] = str_replace(' ', '', iconv("GBK", "utf-8", $xl->sheets[0]['cells'][$i][2]));
        $data['STU_DEP'] = str_replace(' ', '', iconv("gb2312", "utf-8", $xl->sheets[0]['cells'][$i][3]));
        $data['STU_PSW'] = $data['STU_NUM'];
        $data['EXAM_YEAR'] = str_replace(' ', '', iconv("gb2312", "utf-8", $xl->sheets[0]['cells'][$i][4]));
        if ($db->insert("stuinfo", $data)) {
            $succeed++;
        } else {
            $lost++;
        }
    }
    $message = "成功导入" . $succeed . "条记录,失败" . $lost . "条";
}
Пример #15
0
 function upload($path = '')
 {
     $path = $this->BaseUrl . '/' . trim($path, '/');
     if (!is_dir($path)) {
         $data['error'] = 'Folder ' . $path . ' does not exist.';
         return $data;
     }
     $up = new FileUpload();
     //设置属性(上传的位置, 大小, 类型, 名是是否要随机生成)
     $up->set("path", $path);
     $up->set("maxsize", 8 * 1024 * 1024);
     if (!empty($this->allowType) && $this->allowType != '*') {
         $up->set("allowtype", explode(',', $this->allowType));
     }
     $up->set("israndname", false);
     if ($up->upload("upfile")) {
         return $up->getFileName();
     } else {
         $data['error'] = $up->getErrorMsg();
     }
     /**/
     return $data;
 }
Пример #16
0
 public function uploadFile()
 {
     $requestsPerHour = 60;
     $key = sprintf('api:%s', Request::getClientIp());
     $get_data = DB::table('limit')->where('ip', $key)->first();
     if (isset($get_data->ip)) {
         $count = $get_data->count;
         $count++;
         DB::table('limit')->where('ip', $key)->update(array('count' => $count));
     } else {
         DB::table('limit')->insert(array('user_id' => Auth::user()->id, 'ip' => $key, 'count' => 0));
     }
     $count = UserMedia::where('user_id', '=', Auth::user()->id)->where('is_deleted', '=', '0')->where('cat', '=', '1')->count();
     //if($count >= 2 && Auth::user()->category_id == 1){
     //	$response = Response::json(array('result'=>false, 'location' => false,'error'=>'Free accounts are only allowed 2 torrents per account.' ));
     //	$response->header('Content-Type', 'application/json');
     //	return $response;
     //}
     $user_media = UserMedia::where('user_id', '=', Auth::user()->id)->where('is_deleted', '=', '0')->get();
     if (count($user_media) != 0) {
         $uma = array();
         foreach ($user_media as $um) {
             array_push($uma, $um->media_id);
         }
         $media_count = Media::whereIn('id', $uma)->where('state', '!=', 'done')->where('state', '!=', 'max_pause')->where('state', '!=', 'failed')->where('state', '!=', 'process')->where('state', '!=', 'stop')->count();
         if ($media_count >= 1 && Auth::user()->category_id == 1) {
             $response = Response::json(array('result' => false, 'location' => false, 'error' => 'Free accounts are only allowed 1 active torrent per account.'));
             $response->header('Content-Type', 'application/json');
             return $response;
         }
         if ($media_count >= 10) {
             $response = Response::json(array('result' => false, 'location' => false, 'error' => 'Your account is only allowed 10 active torrents.'));
             $response->header('Content-Type', 'application/json');
             return $response;
         }
     }
     if (Auth::user()->category_id == 1) {
         $status = true;
         $useage = Auth::user()->used_bytes;
         if ($useage > Auth::user()->avl_bytes) {
             $status = false;
         }
         if (Auth::user()->avl_bytes - $useage < 104857600) {
             $status = false;
         }
         date_default_timezone_set('Pacific/Auckland');
         $ip_date = date("Y-m-d");
         $ip_bytes = DataIp::where('ip', '=', $_SERVER['REMOTE_ADDR'])->where('date', '=', $ip_date)->sum('bytes');
         if (1073741824 - $ip_bytes < 104857600) {
             $status = false;
         }
         if (!$status) {
             $response = Response::json(array('result' => false, 'location' => false, 'error' => 'Low bandwidth left on your account. Upgrade your account to premium.'));
             $response->header('Content-Type', 'application/json');
             return $response;
         }
     }
     require '/opt/nginx/html/vendor/upload.php';
     $upload_directory = '/opt/nginx/html/public/cache/tmp';
     $allowed_extensions = array('torrent');
     $max_size = 1048576;
     $uploader = new FileUpload('file');
     $ext = $uploader->getExtension();
     if (empty($ext)) {
         $response = Response::json(array('result' => false, 'location' => false, 'error' => 'Invalid file type.'));
         $response->header('Content-Type', 'application/json');
         return $response;
     }
     $filename = uniqid(uniqid(), true) . '.' . $ext;
     $uploader->newFileName = $filename;
     $uploader->sizeLimit = $max_size;
     $result = $uploader->handleUpload($upload_directory, $allowed_extensions);
     $errors = $uploader->getErrorMsg();
     if (!empty($errors)) {
         $response = Response::json(array('result' => false, 'location' => false, 'error' => $uploader->getErrorMsg()));
         $response->header('Content-Type', 'application/json');
         return $response;
     }
     $file = $uploader->getSavedFile();
     $url = 'http://s01.okaydrive.com/rt/php/addtorrent2.php';
     $myvars = 'torrents_start_stopped=1&url=https://okaydrive.com/cache/tmp/' . $filename;
     $ch = curl_init($url);
     $username = '******';
     $password = '******';
     curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
     curl_setopt($ch, CURLOPT_POST, 1);
     curl_setopt($ch, CURLOPT_POSTFIELDS, $myvars);
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
     curl_setopt($ch, CURLOPT_HEADER, 0);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     $response = curl_exec($ch);
     $json = json_decode($response, true);
     $uni_id = '';
     if ($json["result"] == "success") {
         $hash = $json["hash"];
         $mediaexist = Media::where('hash', '=', $hash)->first();
         if (isset($mediaexist->id)) {
             if ($mediaexist->state == 'done' || $mediaexist->state == 'failed') {
                 $url = 'http://s01.okaydrive.com/rt/plugins/httprpc/action.php';
                 $myvars = 'mode=remove&hash=' . $mediaexist->hash;
                 $ch = curl_init($url);
                 $username = '******';
                 $password = '******';
                 curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
                 curl_setopt($ch, CURLOPT_POST, 1);
                 curl_setopt($ch, CURLOPT_POSTFIELDS, $myvars);
                 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
                 curl_setopt($ch, CURLOPT_HEADER, 0);
                 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
                 curl_setopt($ch, CURLOPT_TIMEOUT, 4);
                 //timeout in seconds
                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                 $response = curl_exec($ch);
                 $removed = json_decode($response, true);
             }
             $userHasMedia = UserMedia::where('user_id', '=', Auth::user()->id)->where('media_id', '=', $mediaexist->id)->first();
             if (!isset($userHasMedia->id)) {
                 if ($mediaexist->size > Auth::user()->category()->max_add) {
                     $response = Response::json(array('result' => false, 'location' => false, 'error' => 'Max torrent size allowed for Free accounts reached.'));
                     $response->header('Content-Type', 'application/json');
                     return $response;
                 }
                 if ($mediaexist->state == 'max_pause') {
                     $mediaexist->state = 'put_pause';
                     $mediaexist->save();
                 }
                 if ($mediaexist->state == 'fail_free' && $mediaexist->user_id != Auth::user()->user_id) {
                     $mediaexist->state = 'put_pause';
                     $mediaexist->save();
                 }
                 if ($mediaexist->state == 'delete') {
                     $mediaexist->state = 'put_pause';
                     $mediaexist->save();
                 }
                 $newMedia = new UserMedia();
                 $newMedia->user_id = Auth::user()->id;
                 $newMedia->cat = Auth::user()->category_id;
                 $newMedia->media_id = $mediaexist->id;
                 $newMedia->uni_id = uniqid(rand(), true);
                 $newMedia->save();
                 $uni_id = $newMedia->uni_id;
                 $res = 'cache';
             } else {
                 if ($mediaexist->state == 'max_pause') {
                     $mediaexist->state = 'put_pause';
                     $mediaexist->save();
                 }
                 if ($mediaexist->state == 'fail_free' && $mediaexist->user_id != Auth::user()->user_id) {
                     $mediaexist->state = 'put_pause';
                     $mediaexist->save();
                 }
                 if ($mediaexist->state == 'delete') {
                     $mediaexist->state = 'put_pause';
                     $mediaexist->save();
                 }
                 if ($userHasMedia->is_deleted) {
                     $userHasMedia->is_deleted = false;
                     $userHasMedia->save();
                 }
                 $uni_id = $userHasMedia->uni_id;
                 $res = 'has';
             }
         } else {
             sleep(4);
             $url = 'http://s01.okaydrive.com/rt/plugins/httprpc/action.php';
             $myvars = 'mode=info&hash=' . $hash;
             $ch = curl_init($url);
             $username = '******';
             $password = '******';
             curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
             curl_setopt($ch, CURLOPT_POST, 1);
             curl_setopt($ch, CURLOPT_POSTFIELDS, $myvars);
             curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
             curl_setopt($ch, CURLOPT_HEADER, 0);
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
             $response = curl_exec($ch);
             $torrent_info = json_decode($response, true);
             if (empty($torrent_info[0]) || !isset($torrent_info[0])) {
                 $torrent_info[0] = $hash;
             }
             $inputTorrent["hash"] = $hash;
             $inputTorrent["title"] = $torrent_info[0];
             $inputTorrent["state"] = 'put_pause';
             $inputTorrent["user_id"] = Auth::user()->id;
             $inputTorrent["source"] = 'https://okaydrive.com/cache/tmp/' . $filename;
             $inputTorrent["cat"] = Auth::user()->category_id;
             $new_media = $this->media->create($inputTorrent);
             $newMedia = new UserMedia();
             $newMedia->user_id = Auth::user()->id;
             $newMedia->cat = Auth::user()->category_id;
             $newMedia->media_id = $new_media->id;
             $newMedia->uni_id = uniqid(rand(), true);
             $newMedia->save();
             $uni_id = $newMedia->uni_id;
             sleep(1);
             $url = 'http://s01.okaydrive.com/rt/plugins/httprpc/action.php';
             $myvars = 'mode=fls&hash=' . $hash;
             $ch = curl_init($url);
             $username = '******';
             $password = '******';
             curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
             curl_setopt($ch, CURLOPT_POST, 1);
             curl_setopt($ch, CURLOPT_POSTFIELDS, $myvars);
             curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
             curl_setopt($ch, CURLOPT_HEADER, 0);
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
             $response = curl_exec($ch);
             $torrent_files = json_decode($response, true);
             $files = $torrent_files;
             $totalSize = $torrent_info[1];
             if (!empty($totalSize)) {
                 if ($totalSize > Auth::user()->category()->max_add) {
                     $newMedia->delete();
                     $new_media->delete();
                     $response = Response::json(array('result' => false, 'location' => false, 'error' => 'Max torrent size allowed for Free accounts reached.'));
                     $response->header('Content-Type', 'application/json');
                     return $response;
                 } else {
                     $new_media["size"] = $totalSize;
                 }
             }
             if (!empty($files) && !empty($torrent_info[2])) {
                 $ignore_first_folder = true;
                 $id = 1;
                 $paths = array();
                 foreach ($files as $file) {
                     if ($file[0] != $hash . '.meta') {
                         if ($torrent_info[3] != 0) {
                             $fd = parse_url(basename($torrent_info[2]) . '/' . $file[0]);
                         } else {
                             $fd = parse_url($file[0]);
                         }
                         $path_parts = pathinfo($fd['path']);
                         $dirs = explode("/", $path_parts['dirname']);
                         for ($i = 0; $i <= count($dirs); $i++) {
                             if (isset($dirs[$i]) && $dirs[$i] != '.') {
                                 $full_path = $this->fullpath($dirs, $i);
                                 if (array_key_exists($full_path, $paths)) {
                                 } else {
                                     $paths[$full_path]["id"] = $id;
                                     $paths[$full_path]["name"] = $dirs[$i];
                                     $prev_path = $this->fullpath($dirs, $i - 1);
                                     if (!isset($paths[$prev_path]["id"])) {
                                         $pv_p = 0;
                                     } else {
                                         $pv_p = $paths[$prev_path]["id"];
                                     }
                                     $new_folder = new MediaFlag();
                                     $new_folder->name = $dirs[$i];
                                     $new_folder->folder_id = $id;
                                     $new_folder->in = $pv_p;
                                     $new_folder->media_id = $new_media->id;
                                     $new_folder->save();
                                     $id++;
                                 }
                             } elseif (isset($dirs[$i]) && $dirs[$i] == '.') {
                                 //echo $path_parts["basename"].' 0';
                                 $new_file = new MediaLike();
                                 if ($torrent_info[3] != 0) {
                                     $new_file->path = basename($torrent_info[2]) . '/' . $file[0];
                                 } else {
                                     $new_file->path = $file[0];
                                 }
                                 $new_file->type = $this->getExt($new_file->path);
                                 $new_file->name = $path_parts["basename"];
                                 $new_file->in = 0;
                                 $new_file->size = $file[3];
                                 $new_file->media_id = $new_media->id;
                                 //$like->user_id = Auth::user()->id;
                                 $new_file->save();
                                 $ignore_first_folder = false;
                             } else {
                                 if (isset($dirs[$i - 1]) && $dirs[$i - 1] != '.') {
                                     $full_path = $this->fullpath($dirs, $i - 1);
                                     //echo $path_parts["basename"].' '.$paths[$full_path]["id"];
                                     $new_file = new MediaLike();
                                     if ($torrent_info[3] != 0) {
                                         $new_file->path = basename($torrent_info[2]) . '/' . $file[0];
                                     } else {
                                         $new_file->path = $file[0];
                                     }
                                     $new_file->type = $this->getExt($new_file->path);
                                     $new_file->name = $path_parts["basename"];
                                     $new_file->in = $paths[$full_path]["id"];
                                     $new_file->size = $file[3];
                                     $new_file->media_id = $new_media->id;
                                     //$like->user_id = Auth::user()->id;
                                     $new_file->save();
                                 }
                             }
                         }
                     }
                 }
                 $new_media["ignore_first"] = $ignore_first_folder;
             }
             $new_media->save();
             $res = 'added';
         }
     } else {
         $error = "Could not add the torrent, please check your input.";
     }
     //$new_media = $this->media->create($input);
     if (isset($error)) {
         $response = Response::json(array('result' => false, 'location' => false, 'error' => $error));
         $response->header('Content-Type', 'application/json');
         return $response;
     } else {
         $response = Response::json(array('result' => true, 'location' => '/torrent/' . $uni_id, 'torrent' => $res));
         $response->header('Content-Type', 'application/json');
         return $response;
     }
 }