Exemplo n.º 1
0
 function upload_file($attractionid, $imageid, $title, $distance, $origin, $dest, $tmp_name, $overwrite = false)
 {
     FileManagerController::_checkPermission();
     $origin = basename($origin);
     $full_dest = $dest . $origin;
     $file_name = $origin;
     for ($i = 1; file_exists($full_dest); $i++) {
         if ($overwrite) {
             unlink($full_dest);
             continue;
         }
         $file_ext = strpos($origin, '.') === false ? '' : '.' . substr(strrchr($origin, '.'), 1);
         $file_name = substr($origin, 0, strlen($origin) - strlen($file_ext)) . '_' . $i . $file_ext;
         $full_dest = $dest . $file_name;
     }
     if (move_uploaded_file($tmp_name, $full_dest)) {
         //Add Banner to database
         $data = $_POST['attraction'];
         Flash::set('post_data', (object) $data);
         if ($imageid == -1) {
             $attractionimage = new AttractionImage();
             $attractionimage->attractionid = $attractionid;
         } else {
             $attractionimage = AttractionImage::findById($imageid);
         }
         $last_seq = $attractionimage->getLastAttractionImageSeq($attractionid);
         $attractionimage->title = $title;
         $attractionimage->distance = $distance;
         $attractionimage->filename = $file_name;
         $attractionimage->filename = $file_name;
         $attractionimage->sequence = $last_seq + 1;
         if (!$attractionimage->save()) {
             Flash::set('error', __('Attraction image has not been added!'));
         } else {
             Flash::set('success', __('Attraction image has been added!'));
         }
         // change mode of the dire to 0644 by default
         chmod($full_dest, 0644);
         return $file_name;
     }
     return false;
 }