public function uploadfiles() { //apakah ada file $adafile = isset($_GET['adafile']) ? $_GET['adafile'] : ''; //cek if ada file if ($adafile) { $if = new InputFileModel(); $uploadpath = $if->upload_location; if (file_exists($uploadpath . $adafile)) { //delete old file if (unlink($uploadpath . $adafile)) { $arrf = $if->getWhere("file_filename = '{$adafile}' LIMIT 0,1"); if (count($arrf) > 0) { $if->delete($arrf[0]->file_id); } //delete from log PortalFileLogger::deleteFileLog($uploadpath . $adafile); /*if(file_exists(_PHOTOPATH.'thumbnail/' . $adafile)) { //delete old thumb file unlink(_PHOTOPATH.'thumbnail/' . $adafile); }*/ } } } $data = array(); //$tid = (isset($_GET['tid'])?addslashes($_GET['tid']):die('no ID')); $t = isset($_GET['t']) ? addslashes($_GET['t']) : die('no t'); $data['files'] = $_GET['files']; $data['bool'] = 0; $dc = new InputFileModel(); if (isset($_GET['files'])) { $error = false; $files = array(); $uploaddir = $dc->upload_location; foreach ($_FILES as $file) { $f = new InputFileModel(); $q = "INSERT INTO {$f->table_name} SET file_folder_id = '0',file_author = '" . Account::getMyID() . "'"; global $db; $fid = $db->qid($q); $f->getByID($fid); if ($fid) { $newname = $fid; $f->file_url = basename($file['name']); $ext = end(explode(".", $file['name'])); $f->file_ext = $ext; $f->file_filename = $fid . "." . $ext; $f->file_date = leap_mysqldate(); // if pdf if (move_uploaded_file($file['tmp_name'], $uploaddir . $f->file_filename)) { $files[] = $uploaddir . $file['name']; $f->file_size = filesize($uploaddir . $f->file_filename); if ($f->file_ext == "pdf") { $a = new PDF2Text(); $a->setFilename($uploaddir . $f->file_filename); $a->decodePDF(); $f->file_isi = preg_replace("/\r|\n/", " ", $a->output()); //the path to the PDF file $strPDF = $uploaddir . $f->file_filename; $thumb = $uploaddir . "thumbs/" . $fid . ".jpg"; exec("convert \"{$strPDF}[0]\" \"{$thumb}\""); } $f->load = 1; $data['bool'] = $f->save(); $data['isImage'] = Leap\View\InputFile::isImage($f->file_filename); $data['filename'] = $f->file_filename; if (isset($_SESSION['target_id']['obj'])) { $target = get_class($_SESSION['target_id']['obj']); } else { $target = "inputfile_unknown"; } PortalFileLogger::save2log($uploaddir . $f->file_filename, $target, $f->file_url); die(json_encode($data)); } else { $error = true; } } } $data = $error ? array('error' => 'There was an error uploading your files') : array('files' => $files); } else { $data = array('success' => 'Form was submitted', 'formData' => $_POST); } echo json_encode($data); }
public function uploadfiles_gallery() { $data = array(); //$tid = (isset($_GET['tid'])?addslashes($_GET['tid']):die('no ID')); $t = isset($_GET['t']) ? addslashes($_GET['t']) : die('no t'); $dc = new InputFileModel(); if (isset($_GET['files'])) { $error = false; $files = array(); $uploaddir = $dc->upload_location; $arrSuc = array(); $arrSucAsli = array(); foreach ($_FILES as $file) { $f = new InputFileModel(); $q = "INSERT INTO {$f->table_name} SET file_folder_id = '0',file_author = '" . Account::getMyID() . "'"; global $db; $fid = $db->qid($q); $f->getByID($fid); if ($fid) { $newname = $fid; $f->file_url = basename($file['name']); $ext = end(explode(".", $file['name'])); $f->file_ext = $ext; $f->file_filename = $fid . "." . $ext; $f->file_date = leap_mysqldate(); $ifn = new \Leap\View\InputFile(); if (in_array($ext, $ifn->arrImgExt)) { $isImage = 1; } else { $isImage = 0; $error = true; } if ($isImage) { if (move_uploaded_file($file['tmp_name'], $uploaddir . $f->file_filename)) { $files[] = $uploaddir . $file['name']; $f->file_size = filesize($uploaddir . $f->file_filename); /* * thumbnail */ $src = $uploaddir . $f->file_filename; $dest = $uploaddir . 'thumbnail/' . $f->file_filename; // $this->make_thumb($src, $dest, 570); $up = new Uploader(); // $up->make_thumb_new() $up->make_thumb_new($src, $dest, 570); $f->load = 1; $f->save(); $arrSuc[] = $f->file_filename; $fil = trim(rtrim($f->file_filename)); $fil2 = explode(".", $fil); $fil3 = $fil2[0]; $arrSucAsli[] = "<div id='file_" . $fid . "_{$t}' class='mlt_item_gal'><div id='gal_{$fil3}' class='foto100gal'><span class='helper'></span><img ondblclick='makeasmainpic_" . $t . "(\"{$fil}\");' src='" . _SPPATH . $f->upload_url . $f->file_filename . "'></div>" . $f->file_url . " <i onclick=\"deleteFromList_{$t}('" . $f->file_filename . "');\" class='glyphicon glyphicon-remove'></i></div>"; if (isset($_SESSION['target_id']['obj'])) { $target = get_class($_SESSION['target_id']['obj']); } else { $target = "inputfile_unknown"; } PortalFileLogger::save2log($uploaddir . $f->file_filename, $target, $f->file_url); } else { $error = true; } } } } $data = $error ? array('error' => 'There was an error uploading your files, make sure your file is an image file') : array('files' => $files, 'ftext' => implode(",", $arrSuc), 'ftextAsli' => implode(" ", $arrSucAsli)); } else { $data = array('success' => 'Form was submitted', 'formData' => $_POST); } echo json_encode($data); }