/** * Run the database seeds. * * @return void */ public function run() { // Eloquent::unguard(); DB::table('pictures')->delete(); DB::statement("ALTER TABLE avatars AUTO_INCREMENT=1"); $dirUploads = public_path(env('UPLOAD_PICTURES', 'uploads')); $files = File::allFiles($dirUploads); foreach ($files as $file) { File::delete($file); } $products = Product::all(); foreach ($products as $product) { $uri = str_random(12) . '_370x235.jpg'; $fileName = file_get_contents('http://lorempixel.com/futurama/370/235'); $pathDirectory = $dirUploads . DIRECTORY_SEPARATOR . $uri; FILE::put($pathDirectory, $fileName); $mime = mime_content_type($dirUploads . DIRECTORY_SEPARATOR . $uri); Picture::create(['product_id' => $product->id, 'uri' => $uri, 'title' => $this->facker->name, 'mime' => $mime, 'size' => 200]); } }
public static function img_remove($path = '') { $s = strpos($path, '/'); //если только имя файла if ($s === FALSE) { $path = PATH_ROOT . PATH_UPLOADS_IMAGES . DS . $path; } else { //если путь не содержит PATH_ROOT if (strpos($path, PATH_ROOT) === FALSE) { $path = PATH_ROOT . DS . $path; } } $path = str_replace('//', DS, $path); if (DS == '\\') { $path = str_replace('\\\\', DS, $path); $path = str_replace('\\/', DS, $path); $path = str_replace('/\\', DS, $path); } if (is_file($path)) { unlink($path); } $name = FILE::name($path); $ext = FILE::ext($path); $path = dirname($path); for ($i = 1; $i <= 10; $i++) { $path_small = $path . DS . 'small' . $i . '_' . $name . '.' . $ext; if (is_file($path_small)) { unlink($path_small); } } }
/** * Delete a Photo * route: /photos/delete{id} * * @param Request $request * @return Response */ public function photoDeleteAction(Request $request) { $path = API_UPLOAD_DIR . '/'; $data = $request->json()->get('Photo'); $failed_ids = array(); $succeeded_ids = array(); foreach ($data['id'] as $photo_id) { $photo = Photos::find($photo_id); if (!$photo || $photo->user_id != $data['user_id']) { $failed_ids[] = $photo_id; continue; } $filename = $photo->url; $fullpath = $path . $filename; try { DB::beginTransaction(); if (FILE::exists($fullpath)) { // Delete an array of files //$files = array($file1, $file2); FILE::delete($fullpath); } // end if Exists $comment = new Comments(); $comment->deleteCommentByType(CONSTANTS::PHOTO, $photo->id); $like = new Like(); $like->deleteLikes(CONSTANTS::PHOTO, $photo->id); $activity = new Activities(); $activity->deleteActivity(CONSTANTS::PHOTO_UPLOAD_RESTAURANT, $photo->id); $photo->delete(); DB::commit(); $succeeded_ids[] = $photo_id; } catch (\Exception $e) { DB::rollback(); return showErrorResponse('Error deleting photo'); } } $json_return[KeyParser::data] = array(KeyParser::success => $succeeded_ids, KeyParser::failed => $failed_ids); return response()->json($json_return); }
public function index() { $this->setView('index.php'); $is_logged = isset(User_Model::$auth_data); $is_student = $is_logged && isset(User_Model::$auth_data['student_number']); $is_admin = $is_logged && User_Model::$auth_data['admin'] == '1'; $this->set(array('username' => User_Model::$auth_data['username'], 'is_logged' => $is_logged, 'is_student' => $is_student, 'is_admin' => $is_admin)); //Fonction qui met à jour l'annuaire dans mysql et ajoute les avatars //$uploaded_files=array(); if (isset($_FILES['uploadzip'])) { if ($_FILES['uploadzip']['size'] > Config::UPLOAD_MAX_SIZE_FILE) { throw new Exception(__('POST_ADD_ERROR_FILE_SIZE', array('size' => File::humanReadableSize(Config::UPLOAD_MAX_SIZE_FILE)))); } //On déplace le fichier zipper vers le serveur if ($filepaths = File::upload('uploadzip')) { // foreach($filepaths as $filepath) // $uploaded_files[] = $filepath; //foreach($filepaths as $i => $filepath){ if (!preg_match('#\\.zip$#', $filepaths)) { throw new Exception(__('POST_ADD_ERROR_FILE_FORMAT')); } $name = $filepaths; //} } $path = DATA_DIR . Config::DIR_DATA_TMP . 'annuaire/'; // On dézip celui-ci if (FILE::exists($path)) { FILE::delete($path); } File::makeDir($path); $zip = new ZipArchive(); $res = $zip->open($name); if ($res === TRUE) { $zip->extractTo($path); $zip->close(); unlink($name); } else { throw new Exception(__('ADMIN_POST_ZIPERROR')); } if (File::delete(DATA_DIR . Config::DIR_DATA_TMP . $name)) { // On aplique le chmod a tous les dossiers et fichiers du zip FILE::chmodDirectory($path, 0); // on traite les fichiers students.csv et users.csv if (file_exists($path . 'users.csv')) { $fp = fopen($path . 'users.csv', "r"); } else { throw new Exception(__('ADMIN_POST_CSVERROR1')); } $i = 0; while (!feof($fp)) { $i = $i + 1; // Tant qu'on n'atteint pas la fin du fichier $ligne = fgets($fp, 4096); /* On lit une ligne */ // On récupère les champs séparés par ; dans liste $liste = explode(";", $ligne); // On assigne les variables if (strlen($liste[0]) > 1) { if (isset($liste[0])) { $username = $liste[0]; } if (isset($liste[1])) { $admin = $liste[1]; } if (isset($liste[2])) { $mail = $liste[2]; } if (isset($liste[3])) { $msn = $liste[3]; } if (isset($liste[4])) { $jabber = $liste[4]; } if (isset($liste[5])) { $address = $liste[5]; } if (isset($liste[6])) { $zipcode = $liste[6]; } if (isset($liste[7])) { $city = $liste[7]; } if (isset($liste[8])) { $cellphone = $liste[8]; } if (isset($liste[9])) { $phone = $liste[9]; } if (isset($liste[10])) { $birthday = $liste[10]; } if (!$this->model->checkuser($username, 1)) { $this->model->insertUsers(trim($username), trim($admin), trim($mail), trim($msn), trim($jabber), trim($address), trim($zipcode), trim($city), trim($cellphone), trim($phone), trim($birthday)); } } } fclose($fp); if (file_exists($path . 'students.csv')) { $fp = fopen($path . 'students.csv', "r"); } else { throw new Exception(__('ADMIN_POST_CSVERROR2')); } $i = 0; while (!feof($fp)) { $i = $i + 1; // Tant qu'on n'atteint pas la fin du fichier $ligne = fgets($fp, 4096); /* On lit une ligne */ // On récupère les champs séparés par ; dans liste $liste = explode(";", $ligne); // On assigne les variables if (strlen($liste[0]) > 1) { if (isset($liste[0])) { $username = $liste[0]; } if (isset($liste[1])) { $lastname = $liste[1]; } if (isset($liste[2])) { $firstname = $liste[2]; } if (isset($liste[3])) { $student_number = $liste[3]; } if (isset($liste[4])) { $promo = $liste[4]; } if (isset($liste[5])) { $cesure = $liste[5]; } if (!$this->model->checkuser($username, 2)) { $this->model->insertStudents(trim($username), trim($lastname), trim($firstname), trim($student_number), trim($promo), trim($cesure)); } // On déplace et formate les photos dans le dossier avatars $avatarpath = $path . 'photos_students/' . $student_number . '.jpg'; $img = new Image(); $img->load($avatarpath); $type = $img->getType(); if ($type == IMAGETYPE_JPEG) { $ext = 'jpg'; } else { if ($type == IMAGETYPE_GIF) { $ext = 'gif'; } else { if ($type == IMAGETYPE_PNG) { $ext = 'png'; } else { throw new Exception(); } } } if ($img->getWidth() > 800) { $img->setWidth(800, true); } $img->setType(IMAGETYPE_JPEG); $img->save($avatarpath); // Thumb $avatarthumbpath = $path . 'photos_students/' . $student_number . '_thumb.jpg'; $img->thumb(Config::$AVATARS_THUMBS_SIZES[0], Config::$AVATARS_THUMBS_SIZES[1]); $img->setType(IMAGETYPE_JPEG); $img->save($avatarthumbpath); if (FILE::exists(DATA_DIR . Config::DIR_DATA_STORAGE . 'avatars/' . substr($student_number, 0, -2) . '/')) { FILE::move($avatarthumbpath, DATA_DIR . Config::DIR_DATA_STORAGE . 'avatars/' . substr($student_number, 0, -2) . '/'); FILE::move($avatarpath, DATA_DIR . Config::DIR_DATA_STORAGE . 'avatars/' . substr($student_number, 0, -2) . '/'); } else { FILE::makeDir(DATA_DIR . Config::DIR_DATA_STORAGE . 'avatars/' . substr($student_number, 0, -2) . '/'); FILE::move($avatarthumbpath, DATA_DIR . Config::DIR_DATA_STORAGE . 'avatars/' . substr($student_number, 0, -2) . '/'); FILE::move($avatarpath, DATA_DIR . Config::DIR_DATA_STORAGE . 'avatars/' . substr($student_number, 0, -2) . '/'); } unset($img); } } fclose($fp); // On supprime le tout du dossier temp FILE::delete($path); } } }
function load_translations($lang, &$l) { $utimer = utime(); $l = new stdClass(); $fn = sprintf("%s/%s.txt", ETC_DIR, $lang); if (file_exists($fn)) { $f = new FILE(); $f->open($fn, 'r'); $e = explode(';', $f->read()); // esimene lõikamine while (list($k, $v) = each($e)) { $val = $chr = ''; $j = explode('=', trim($v)); $k = trim($j['0']); // esimene element if (count($j) > 0) { for ($i = 1; $i < count($j); $i++) { $val .= $chr . $j[$i]; $chr = '='; } } else { $val = $j['1']; } if (!empty($k)) { $l->{$k} = trim($val); } } $f->close(); unset($f); unset($e); /* echo "<!--"; print_r($l); echo "-->"; */ $t = stop_utimer($utimer); return true; } return false; }
public function usersPage($param) { $this->setView('users.php'); /* * Enregistrement du post dans la table users */ if (isset($_FILES['uploadxml1']) && $_FILES['uploadxml1']['name'] != null) { if ($_FILES['uploadxml1']['size'] > Config::UPLOAD_MAX_SIZE_FILE) { throw new Exception(__('POST_ADD_ERROR_FILE_SIZE', array('size' => File::humanReadableSize(Config::UPLOAD_MAX_SIZE_FILE)))); } //On déplace le fichier vers le serveur if ($filepaths = File::upload('uploadxml1')) { if (!preg_match('#\\.xml$#', $filepaths)) { throw new Exception(__('POST_ADD_ERROR_FILE_FORMAT')); } $name = $filepaths; } $student = array(); $path = DATA_DIR . Config::DIR_DATA_TMP . $_FILES['uploadxml1']['name']; if (file_exists($path)) { $data = simplexml_load_file($path); foreach ($data->data as $data) { if (isset($data->username) && isset($data->admin) && isset($data->mail) && isset($data->msn) && isset($data->jabber) && isset($data->address) && isset($data->address) && isset($data->zipcode) && isset($data->city) && isset($data->cellphone) && isset($data->phone) && isset($data->birthday)) { $username = $data->username; $admin = $data->admin; $mail = $data->mail; $msn = $data->msn; $jabber = $data->jabber; $address = $data->address; $zipcode = $data->zipcode; $city = $data->city; $cellphone = $data->cellphone; $phone = $data->phone; $birthday = $data->birthday; if (!$this->model->checkuser($username, 1)) { $this->model->insertUsers($username, $admin, utf8_decode($mail), utf8_decode($msn), utf8_decode($jabber), utf8_decode($address), $zipcode, $city, $cellphone, $phone, $birthday); } else { array_push($student, $username); } } else { throw new Exception(__('ADMIN_UPLOAD_ERROR2')); } } } else { throw new Exception(__('ADMIN_UPLOAD_ERROR')); } FILE::delete($path); $this->set('fail', $student); } /* * Enregistrement du post dans la table students */ if (isset($_FILES['uploadxml2']) && $_FILES['uploadxml2']['name'] != null) { if ($_FILES['uploadxml2']['size'] > Config::UPLOAD_MAX_SIZE_FILE) { throw new Exception(__('POST_ADD_ERROR_FILE_SIZE', array('size' => File::humanReadableSize(Config::UPLOAD_MAX_SIZE_FILE)))); } if ($filepaths = File::upload('uploadxml2')) { if (!preg_match('#\\.xml$#', $filepaths)) { throw new Exception(__('POST_ADD_ERROR_FILE_FORMAT')); } $name = $filepaths; } $student = array(); $path = DATA_DIR . Config::DIR_DATA_TMP . $_FILES['uploadxml2']['name']; if (file_exists($path)) { $data = simplexml_load_file($path); foreach ($data->data as $data) { if (isset($data->username) && isset($data->lastname) && isset($data->firstname) && isset($data->student_number) && isset($data->promo) && isset($data->cesure)) { $username = $data->username; $lastname = $data->lastname; $firstname = $data->firstname; $student_number = $data->student_number; $promo = $data->promo; $cesure = $data->cesure; if (!$this->model->checkuser($username, 2)) { $this->model->insertStudents($username, utf8_decode($lastname), utf8_decode($firstname), $student_number, $promo, $cesure); } else { array_push($student, $username); } } else { throw new Exception(__('ADMIN_UPLOAD_ERROR2')); } } } else { throw new Exception(__('ADMIN_UPLOAD_ERROR')); } FILE::delete($path); $this->set('fail', $student); } /* * Enregistrement des avatars */ if (isset($_FILES['avatar_photo']) && is_array($_FILES['avatar_photo']['name'])) { foreach ($_FILES['avatar_photo']['size'] as $size) { if ($size > Config::UPLOAD_MAX_SIZE_PHOTO) { throw new Exception(__('POST_ADD_ERROR_PHOTO_SIZE', array('size' => File::humanReadableSize(Config::UPLOAD_MAX_SIZE_PHOTO)))); } } $student = array(); if ($avatarpaths = File::upload('avatar_photo')) { foreach ($avatarpaths as $avatarpath) { $uploaded_files[] = $avatarpath; } foreach ($avatarpaths as $i => $avatarpath) { $name = $_FILES['avatar_photo']['name'][$i]; try { $img = new Image(); $img->load($avatarpath); $type = $img->getType(); if ($type == IMAGETYPE_JPEG) { $ext = 'jpg'; } else { if ($type == IMAGETYPE_GIF) { $ext = 'gif'; } else { if ($type == IMAGETYPE_PNG) { $ext = 'png'; } else { throw new Exception(); } } } if ($img->getWidth() > 800) { $img->setWidth(800, true); } $img->setType(IMAGETYPE_JPEG); $img->save($avatarpath); // Thumb $avatarthumbpath = $avatarpath . '.thumb'; $img->thumb(Config::$AVATARS_THUMBS_SIZES[0], Config::$AVATARS_THUMBS_SIZES[1]); $img->setType(IMAGETYPE_JPEG); $img->save($avatarthumbpath); unset($img); $uploaded_files[] = $avatarthumbpath; $student_data['avatar_path'] = $avatarthumbpath; $student_data['avatar_big_path'] = $avatarpath; $student_data['student_number'] = preg_replace('/\\.[a-z0-9]+$/i', '', $name); if (isset($student_data['avatar_path']) && isset($student_data['student_number']) && File::exists($student_data['avatar_path'])) { $avatar_path = Student_Model::getAvatarPath((int) $student_data['student_number'], true); $avatar_dir = File::getPath($avatar_path); if (!is_dir($avatar_dir)) { File::makeDir($avatar_dir, 0777, true); } File::rename($student_data['avatar_path'], $avatar_path); } if (isset($student_data['avatar_big_path']) && isset($student_data['student_number']) && File::exists($student_data['avatar_big_path'])) { $avatar_path = Student_Model::getAvatarPath((int) $student_data['student_number'], false); $avatar_dir = File::getPath($avatar_path); if (!is_dir($avatar_dir)) { File::makeDir($avatar_dir, 0777, true); } File::rename($student_data['avatar_big_path'], $avatar_path); } } catch (Exception $e) { array_push($student, $name); } } $this->set('fail2', $student); foreach ($uploaded_files as $uploaded_file) { File::delete($uploaded_file); } } } }
/** * This unlocks a locked file pointer. * * @access public * @param string $filename The filename that was opened * @param string $mode Mode the file was opened in * @return mixed PEAR Error on error, true otherwise */ function unlock($filename, $mode) { if (!PEAR::isError($fp =& FILE::_getFilePointer($filename, $mode))) { return flock($fp, LOCK_UN) ? true : PEAR::raiseError('Failed to unlock file: ' . $filename); } return $fp; }