ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjFile.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once "Services/Object/classes/class.ilObject2.php";
5 include_once('Modules/File/classes/class.ilFSStorageFile.php');
6 
18 class ilObjFile extends ilObject2
19 {
20  var $filename;
21  var $filetype;
22  var $filemaxsize = "20000000"; // not used yet
24  var $mode = "object";
25 
26  private $file_storage = null;
27 
28 
35  function __construct($a_id = 0,$a_call_by_reference = true)
36  {
37  $this->version = 0;
38  $this->raise_upload_error = true;
39  parent::__construct($a_id,$a_call_by_reference);
40 
41  if($this->getId())
42  {
43  $this->initFileStorage();
44  }
45  }
46 
47  function initType()
48  {
49  $this->type = "file";
50  }
51 
57  protected function doCreate($a_upload = false, $a_prevent_meta_data_creation = false)
58  {
59  //BEGIN WebDAV Move Property creation into a method of its own.
60  $this->createProperties($a_upload);
61  //END WebDAV Move Property creation into a method of its own.
62  }
63 
64  //BEGIN WebDAV: Move Property creation into a method of its own.
72  function createProperties($a_upload = false, $a_prevent_meta_data_creation = false)
73  {
74  global $ilDB,$tree;
75 
76  // Create file directory
77  $this->initFileStorage();
78  $this->file_storage->create();
79 
80  if($a_upload)
81  {
82  return true;
83  }
84 
85  // not upload mode
86  require_once("classes/class.ilHistory.php");
87  ilHistory::_createEntry($this->getId(), "create", $this->getFileName().",1");
88  $this->addNewsNotification("file_created");
89 
90 
91  require_once("./Services/News/classes/class.ilNewsItem.php");
92  $default_visibility = ilNewsItem::_getDefaultVisibilityForRefId($_GET['ref_id']);
93  if ($default_visibility == "public")
94  {
95  ilBlockSetting::_write("news", "public_notifications",
96  1, 0, $this->getId());
97  }
98 
99  $q = "INSERT INTO file_data (file_id,file_name,file_type,file_size,version,f_mode) "
100  ."VALUES (".$ilDB->quote($this->getId() ,'integer').","
101  .$ilDB->quote($this->getFileName() ,'text').","
102  .$ilDB->quote($this->getFileType() ,'text').","
103  .$ilDB->quote((int) $this->getFileSize() ,'integer').","
104  .$ilDB->quote(1 ,'integer').",".$ilDB->quote($this->getMode() ,'text').")";
105  $res = $ilDB->manipulate($q);
106 
107  // no meta data handling for file list files
108  if ($this->getMode() != "filelist" && !$a_prevent_meta_data_creation)
109  {
110  $this->createMetaData();
111  }
112  }
113  //END WebDAV: Move Property creation into a method of its own.
114 
118  protected function doCreateMetaData()
119  {
120  // add technical section with file size and format
121  $md_obj =& new ilMD($this->getId(),0,$this->getType());
122  $technical = $md_obj->addTechnical();
123  $technical->setSize($this->getFileSize());
124  $technical->save();
125  $format = $technical->addFormat();
126  $format->setFormat($this->getFileType());
127  $format->save();
128  $technical->update();
129  }
130 
131  protected function beforeMDUpdateListener($a_element)
132  {
133  // Check file extension
134  // Removing the file extension is not allowed
135  include_once 'Services/MetaData/classes/class.ilMD.php';
136  $md = new ilMD($this->getId(),0, $this->getType());
137  if(!is_object($md_gen = $md->getGeneral()))
138  {
139  return false;
140  }
141  $title = $this->checkFileExtension($this->getFileName(), $md_gen->getTitle());
142  $md_gen->setTitle($title);
143  $md_gen->update();
144  return true;
145  }
146 
147  protected function doMDUpdateListener($a_element)
148  {
149  // handling for technical section
150  include_once 'Services/MetaData/classes/class.ilMD.php';
151 //echo "-".$a_element."-";
152  switch($a_element)
153  {
154  case 'Technical':
155 
156  // Update Format (size is not stored in db)
157  $md = new ilMD($this->getId(),0, $this->getType());
158  if(!is_object($md_technical = $md->getTechnical()))
159  {
160  return false;
161  }
162 
163  foreach($md_technical->getFormatIds() as $id)
164  {
165  $md_format = $md_technical->getFormat($id);
166  ilObjFile::_writeFileType($this->getId(),$md_format->getFormat());
167  $this->setFileType($md_format->getFormat());
168  break;
169  }
170 
171  break;
172  }
173  return true;
174  }
175 
176 
177  function getDirectory($a_version = 0)
178  {
179  $version_subdir = "";
180 
181  if ($a_version)
182  {
183  // BEGIN WebDAV Avoid double slash before version subdirectory
184  $version_subdir = sprintf("%03d", $a_version);
185  // END WebDAV Avoid double slash before version subdirectory
186  }
187 
188  if(!is_object($this->file_storage))
189  {
190  $this->initFileStorage();
191  }
192 
193  return $this->file_storage->getAbsolutePath().'/'.$version_subdir;
194  }
195 
196  function createDirectory()
197  {
199  }
200 
201  function raiseUploadError($a_raise = true)
202  {
203  $this->raise_upload_error = $a_raise;
204  }
205 
206  function getUploadFile($a_upload_file, $a_filename)
207  {
208  $this->setVersion($this->getVersion() + 1);
209 
210  if (@!is_dir($this->getDirectory($this->getVersion())))
211  {
213  }
214 
215  $file = $this->getDirectory($this->getVersion())."/".$a_filename;
216  //move_uploaded_file($a_upload_file, $file);
217  ilUtil::moveUploadedFile($a_upload_file, $a_filename, $file, $this->raise_upload_error);
218  }
219 
223  function replaceFile($a_upload_file, $a_filename)
224  {
225  $this->getUploadFile($a_upload_file, $a_filename);
226 
227  require_once("classes/class.ilHistory.php");
229  $this->getId(),
230  "replace",
231  $a_filename.",".$this->getVersion()
232  );
233  $this->setFilename($a_filename);
234  $this->addNewsNotification("file_updated");
235  }
236 
237 
238  public function addFileVersion($a_upload_file,$a_filename)
239  {
240  $this->getUploadFile($a_upload_file, $a_filename);
241 
242  require_once("classes/class.ilHistory.php");
244  $this->getId(),
245  "new_version",
246  $a_filename.",".$this->getVersion()
247  );
248  $this->setFilename($a_filename);
249  $this->addNewsNotification("file_updated");
250 
251  }
252 
253 
257  function copy($a_source,$a_destination)
258  {
259  return copy($a_source,$this->getDirectory()."/".$a_destination);
260  }
261 
266  {
267  ilUtil::delDir($this->getDirectory());
268  $this->createDirectory();
269  }
270 
271  public function deleteVersions()
272  {
273  global $ilDB;
274 
275  $ilDB->manipulate("UPDATE file_data SET version = 1 WHERE file_id = ".$ilDB->quote($this->getId() ,'integer'));
276  $this->setVersion(0);
277  $this->clearDataDirectory();
278 
279  require_once("classes/class.ilHistory.php");
281 
282  }
283 
287  protected function doRead()
288  {
289  global $ilDB;
290 
291  $q = "SELECT * FROM file_data WHERE file_id = ".$ilDB->quote($this->getId() ,'integer');
292  $r = $this->ilias->db->query($q);
293  $row = $r->fetchRow(DB_FETCHMODE_OBJECT);
294 
295  $this->setFileName($row->file_name);
296  $this->setFileType($row->file_type);
297  $this->setFileSize($row->file_size);
298  $this->setVersion($row->version);
299  $this->setMode($row->f_mode);
300 
301  $this->initFileStorage();
302  }
303 
304  protected function beforeUpdate()
305  {
306  // no meta data handling for file list files
307  if ($this->getMode() != "filelist")
308  {
309  $this->updateMetaData();
310  }
311 
312  return true;
313  }
314 
318  protected function doUpdate()
319  {
320  global $ilDB, $ilLog;
321 
322  //$ilLog->write(__METHOD__.' File type: '.$this->getFileType());
323 
324  $q = "UPDATE file_data SET file_name = ".$ilDB->quote($this->getFileName() ,'text').
325  ", file_type = ".$ilDB->quote($this->getFiletype() ,'text')." ".
326  ", file_size = ".$ilDB->quote((int) $this->getFileSize() ,'integer')." ".
327  ", version = ".$ilDB->quote($this->getVersion() ,'integer')." ".
328  ", f_mode = ".$ilDB->quote($this->getMode() ,'text')." ".
329  "WHERE file_id = ".$ilDB->quote($this->getId() ,'integer');
330  $res = $ilDB->manipulate($q);
331 
332  return true;
333  }
334 
338  protected function doUpdateMetaData()
339  {
340  // add technical section with file size and format
341  $md_obj =& new ilMD($this->getId(),0,$this->getType());
342  if(!is_object($technical = $md_obj->getTechnical()))
343  {
344  $technical = $md_obj->addTechnical();
345  $technical->save();
346  }
347  $technical->setSize($this->getFileSize());
348 
349  $format_ids = $technical->getFormatIds();
350  if (count($format_ids) > 0)
351  {
352  $format = $technical->getFormat($format_ids[0]);
353  $format->setFormat($this->getFileType());
354  $format->update();
355  }
356  else
357  {
358  $format = $technical->addFormat();
359  $format->setFormat($this->getFileType());
360  $format->save();
361  }
362  $technical->update();
363  }
364 
368  function setFileName($a_name)
369  {
370  $this->filename = $a_name;
371  }
372 
373  function getFileName()
374  {
375  return $this->filename;
376  }
377 
378  function setFileType($a_type)
379  {
380  global $ilLog;
381 
382 
383  $this->filetype = $a_type;
384  }
385 
386  function getFileType()
387  {
388  return $this->filetype;
389  }
390 
391  function setFileSize($a_size)
392  {
393  $this->filesize = $a_size;
394  }
395 
396  function getFileSize()
397  {
398  return $this->filesize;
399  }
406  function getDiskUsage()
407  {
408  require_once("./Modules/File/classes/class.ilObjFileAccess.php");
409  return ilObjFileAccess::_lookupDiskUsage($this->id);
410  }
411 
412 
413  // END PATCH WebDAV Encapsulate file access in ilObjFile class.
414  function getFile($a_hist_entry_id = null)
415  {
416  if (is_null($a_hist_entry_id))
417  {
418  $file = $this->getDirectory($this->getVersion())."/".$this->getFileName();
419  }
420  else
421  {
422  require_once("classes/class.ilHistory.php");
423  $entry = ilHistory::_getEntryByHistoryID($a_hist_entry_id);
424 
425  if ($entry === false)
426  {
427  return false;
428  }
429 
430  $data = explode(",",$entry["info_params"]);
431 
432  // bugfix: first created file had no version number
433  // this is a workaround for all files created before the bug was fixed
434  if (empty($data[1]))
435  {
436  $data[1] = "1";
437  }
438 
439  $file = $this->getDirectory($data[1])."/".$data[0];
440  }
441  return $file;
442  }
443  // END PATCH WebDAV Encapsulate file access in ilObjFile class.
444 
445  function setVersion($a_version)
446  {
447  $this->version = $a_version;
448  }
449 
450  function getVersion()
451  {
452  return $this->version;
453  }
454 
460  function setMode($a_mode)
461  {
462  $this->mode = $a_mode;
463  }
464 
470  function getMode()
471  {
472  return $this->mode;
473  }
474 
475  function _writeFileType($a_id ,$a_format)
476  {
477  global $ilDB;
478 
479  $q = "UPDATE file_data SET ".
480  " file_type = ".$ilDB->quote($a_format ,'text').
481  " WHERE file_id = ".$ilDB->quote($a_id ,'integer');
482  $res = $ilDB->manipulate($q);
483 
484  }
485 
486  function _lookupFileName($a_id)
487  {
488  global $ilDB;
489 
490  $q = "SELECT * FROM file_data WHERE file_id = ".$ilDB->quote($a_id ,'integer');
491  $r = $ilDB->query($q);
492  $row = $r->fetchRow(DB_FETCHMODE_OBJECT);
493 
494  return ilUtil::stripSlashes($row->file_name);
495  }
496 
497 
499  function _lookupFileSize($a_id)
500  {
501  require_once("./Modules/File/classes/class.ilObjFileAccess.php");
502  return ilObjFileAccess::_lookupFileSize($a_id);
503  }
504 
508  function _lookupVersion($a_id)
509  {
510  require_once("./Modules/File/classes/class.ilObjFileAccess.php");
511  return ilObjFileAccess::_lookupVersion($a_id);
512  }
513 
517  function determineFileSize($a_hist_entry_id = null)
518  {
519  if (is_null($a_hist_entry_id))
520  {
521  $file = $this->getDirectory($this->getVersion())."/".$this->getFileName();
522  }
523  else
524  {
525  require_once("classes/class.ilHistory.php");
526  $entry = ilHistory::_getEntryByHistoryID($a_hist_entry_id);
527 
528  if ($entry === false)
529  {
530  return false;
531  }
532 
533  $data = explode(",",$entry["info_params"]);
534 
535  // bugfix: first created file had no version number
536  // this is a workaround for all files created before the bug was fixed
537  if (empty($data[1]))
538  {
539  $data[1] = "1";
540  }
541  $file = $this->getDirectory($data[1])."/".$data[0];
542  }
543  $this->setFileSize(filesize($file));
544  }
545 
546  function sendFile($a_hist_entry_id = null)
547  {
548  if (is_null($a_hist_entry_id))
549  {
550  $file = $this->getDirectory($this->getVersion())."/".$this->getFileName();
551 
552  // if not found lookup for file in file object's main directory for downward c ompability
553  if (@!is_file($file))
554  {
555  $file = $this->getDirectory()."/".$this->getFileName();
556  }
557  }
558  else
559  {
560  require_once("classes/class.ilHistory.php");
561  $entry = ilHistory::_getEntryByHistoryID($a_hist_entry_id);
562 
563  if ($entry === false)
564  {
565  echo "3";return false;
566  }
567 
568  $data = explode(",",$entry["info_params"]);
569 
570  // bugfix: first created file had no version number
571  // this is a workaround for all files created before the bug was fixed
572  if (empty($data[1]))
573  {
574  $data[1] = "1";
575  }
576 
577  $file = $this->getDirectory($data[1])."/".$data[0];
578 
579  // if not found lookup for file in file object's main directory for downward compability
580  if (@!is_file($file))
581  {
582  $file = $this->getDirectory()."/".$data[0];
583  }
584 
585  // BEGIN WebDAV removed duplicated code
586  // END WebDAV removed duplicated code
587  }
588 
589  if (@is_file($file))
590  {
591  global $ilClientIniFile;
592  if ($ilClientIniFile->readVariable('file_access','download_with_uploaded_filename') != '1')
593  {
594  ilUtil::deliverFile($file, $this->getTitle(), $this->guessFileType($file), $this->isInline());
595  }
596  else
597  {
598  ilUtil::deliverFile($file, basename($file), $this->guessFileType($file), $this->isInline());
599  }
600  return true;
601  }
602 
603  return false;
604  }
605 
606  // BEGIN WebDAV: Get file extension, determine if file is inline, guess file type.
611  function getFileExtension() {
612  require_once 'class.ilObjFileAccess.php';
614  }
620  function isInline() {
621  require_once 'class.ilObjFileAccess.php';
622  return ilObjFileAccess::_isFileInline($this->getTitle());
623  }
627  function isHidden() {
628  require_once 'class.ilObjFileAccess.php';
629  return ilObjFileAccess::_isFileHidden($this->getTitle());
630  }
631  // END WebDAV: Get file extension, determine if file is inline, guess file type.
632 
639  function guessFileType($a_file = "") {
640 
641  $path = pathinfo($a_file);
642  if ($path["extension"] != "")
643  {
644  $filename = $path["basename"];
645  }
646  else
647  {
648  $filename = "dummy.".$this->getFileExtension();
649  }
650  include_once("./Services/Utilities/classes/class.ilMimeTypeUtil.php");
651  $mime = ilMimeTypeUtil::getMimeType($a_file, $filename, $this->getFileType());
652  return $mime;
653 
654 /*
655  $fileType = $this->getFileType();
656  if (strlen($fileType) == 0) {
657  $fileType = 'application/octet-stream';
658  }
659 
660  // Firefox browser assigns 'application/x-pdf' to PDF files, but
661  // it can only handle them if the have the mime-type 'application/pdf'.
662  if ($fileType == 'application/x-pdf')
663  {
664  $fileType = 'application/pdf';
665  }
666 
667  if ($fileType == 'application/octet-stream')
668  {
669  $fileExtension = $this->getFileExtension();
670  $mimeArray = array(
671  'mpeg' => 'video/mpeg',
672  'mp3' => 'audio/mpeg',
673  'pdf' => 'application/pdf',
674  'gif' => 'image/gif',
675  'jpg' => 'image/jpg',
676  'png' => 'image/png',
677  'htm' => 'text/html',
678  'html' => 'text/html',
679  'wma' => 'video/x-ms-wma',
680  'wmv' => 'video/x-ms-wmv',
681  'swf' => 'application/x-shockwave-flash',
682  );
683  if (array_key_exists($fileExtension, $mimeArray))
684  {
685  $fileType = $mimeArray[$fileExtension];
686  }
687  }
688  return $fileType;
689 */
690  }
691 
701  protected function doCloneObject($a_new_obj,$a_target_id,$a_copy_id = 0)
702  {
703  global $ilDB;
704 
705  $a_new_obj->createDirectory();
706  $this->cloneMetaData($a_new_obj);
707 
708  // Copy all file versions
709  ilUtil::rCopy($this->getDirectory(),$a_new_obj->getDirectory());
710 
711  // object created now copy other settings
712  $query = "INSERT INTO file_data (file_id,file_name,file_type,file_size,version,f_mode) VALUES (".
713  $ilDB->quote($a_new_obj->getId() ,'integer').",".
714  $ilDB->quote($this->getFileName() ,'text').",".
715  $ilDB->quote($this->getFileType() ,'text').",".
716  $ilDB->quote((int) $this->getFileSize() ,'integer').", ".
717  $ilDB->quote($this->getVersion() ,'integer').", ".
718  $ilDB->quote($this->getMode() ,'text').")";
719  $res = $ilDB->manipulate($query);
720 
721  // copy history entries
722  require_once("classes/class.ilHistory.php");
723  ilHistory::_copyEntriesForObject($this->getId(),$a_new_obj->getId());
724 
725  // add news notification
726  $a_new_obj->addNewsNotification("file_created");
727 
728  return $a_new_obj;
729  }
730 
731  protected function beforeDelete()
732  {
733  global $ilDB;
734 
735  // check, if file is used somewhere
736  $usages = $this->getUsages();
737  if (count($usages) == 0)
738  {
739  return true;
740  }
741  return false;
742  }
743 
744  protected function doDelete()
745  {
746  global $ilDB;
747 
748  // delete file data entry
749  $q = "DELETE FROM file_data WHERE file_id = ".$ilDB->quote($this->getId() ,'integer');
750  $this->ilias->db->query($q);
751 
752  // delete history entries
753  require_once("classes/class.ilHistory.php");
755 
756  // delete entire directory and its content
757  if (@is_dir($this->getDirectory()))
758  {
759  ilUtil::delDir($this->getDirectory());
760  }
761 
762  // delete meta data
763  if ($this->getMode() != "filelist")
764  {
765  $this->deleteMetaData();
766  }
767  }
768 
776  function export($a_target_dir)
777  {
778  $subdir = "il_".IL_INST_ID."_file_".$this->getId();
779  ilUtil::makeDir($a_target_dir."/objects/".$subdir);
780 
781  $filedir = $this->getDirectory($this->getVersion());
782 
783  if (@!is_dir($filedir))
784  {
785  $filedir = $this->getDirectory();
786  }
787 
788  ilUtil::rCopy($filedir, $a_target_dir."/objects/".$subdir);
789  }
790 
794  function _deleteAllUsages($a_type, $a_id, $a_usage_hist_nr = 0)
795  {
796  global $ilDB;
797 
798  $ilDB->manipulate("DELETE FROM file_usage WHERE usage_type = ".
799  $ilDB->quote($a_type, "text").
800  " AND usage_id = ".$ilDB->quote((int) $a_id, "integer").
801  " AND usage_hist_nr = ".$ilDB->quote((int) $a_usage_hist_nr, "integer"));
802  }
803 
807  function _saveUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr = 0)
808  {
809  global $ilDB;
810 
811  $ilDB->manipulate("DELETE FROM file_usage WHERE usage_type = ".
812  $ilDB->quote((string) $a_type, "text").
813  " AND usage_id = ".$ilDB->quote((int) $a_id, "integer").
814  " AND usage_hist_nr = ".$ilDB->quote((int) $a_usage_hist_nr, "integer").
815  " AND id = ".$ilDB->quote((int) $a_mob_id, "integer"));
816 
817  $ilDB->manipulate("INSERT INTO file_usage (id, usage_type, usage_id, usage_hist_nr) VALUES".
818  " (".$ilDB->quote((int) $a_mob_id, "integer").",".
819  $ilDB->quote((string) $a_type, "text").",".
820  $ilDB->quote((int) $a_id, "integer").",".
821  $ilDB->quote((int) $a_usage_hist_nr, "integer").")");
822  }
823 
827  function getUsages()
828  {
829  global $ilDB;
830 
831  // get usages in learning modules
832  $q = "SELECT * FROM file_usage WHERE id = ".$ilDB->quote($this->getId(), "integer");
833  $us_set = $ilDB->query($q);
834  $ret = array();
835  while($us_rec = $ilDB->fetchAssoc($us_set))
836  {
837  $ret[] = array("type" => $us_rec["usage_type"],
838  "id" => $us_rec["usage_id"],
839  "hist_nr" => $us_rec["usage_hist_nr"]);
840  }
841 
842  return $ret;
843  }
844 
853  function _getFilesOfObject($a_type, $a_id, $a_usage_hist_nr = 0)
854  {
855  global $ilDB;
856 
857  // get usages in learning modules
858  $q = "SELECT * FROM file_usage WHERE ".
859  "usage_id = ".$ilDB->quote((int) $a_id, "integer")." AND ".
860  "usage_type = ".$ilDB->quote((string) $a_type, "text")." AND ".
861  "usage_hist_nr = ".$ilDB->quote((int) $a_usage_hist_nr, "integer");
862  $file_set = $ilDB->query($q);
863  $ret = array();
864  while($file_rec = $ilDB->fetchAssoc($file_set))
865  {
866  $ret[$file_rec["id"]] = $file_rec["id"];
867  }
868 
869  return $ret;
870  }
871 
872  // TODO: What is this function good for??
873  function getXMLZip()
874  {
875  global $ilias;
876 
877  $zip = PATH_TO_ZIP;
878 
879  exec($zip.' '.ilUtil::escapeShellArg($this->getDirectory().'/'.$this->getFileName())." ".
880  ilUtil::escapeShellArg($this->getDirectory().'/'.'1.zip'));
881 
882  return $this->getDirectory().'/1.zip';
883  }
884 
885  function addNewsNotification($a_lang_var)
886  {
887  // BEGIN WebDAV Suppress news notification for hidden files
888  if ($this->isHidden()) {
889  return;
890  }
891  // END WebDAV Suppress news notification for hidden files
892 
893  global $ilUser;
894 
895  // Add Notification to news
896  include_once("./Services/News/classes/class.ilNewsItem.php");
897  include_once("./Modules/File/classes/class.ilObjFileAccess.php");
898  $news_item = new ilNewsItem();
899  $news_item->setContext($this->getId(), $this->getType());
900  $news_item->setPriority(NEWS_NOTICE);
901  $news_item->setTitle($a_lang_var);
902  $news_item->setContentIsLangVar(true);
903  if ($this->getDescription() != "")
904  {
905  $news_item->setContent(
906  "<p>".
907  $this->getDescription()."</p>");
908  }
909  $news_item->setUserId($ilUser->getId());
910  $news_item->setVisibility(NEWS_USERS);
911  $news_item->create();
912  }
913 
920  public function initFileStorage()
921  {
922  $this->file_storage = new ilFSStorageFile($this->getId());
923  return true;
924  }
934  function storeUnzipedFile($a_upload_file, $a_filename)
935  {
936  $this->setVersion($this->getVersion() + 1);
937 
938  if (@!is_dir($this->getDirectory($this->getVersion())))
939  {
940  ilUtil::makeDir($this->getDirectory($this->getVersion()));
941  }
942 
943  $file = $this->getDirectory($this->getVersion())."/".$a_filename;
944  //move_uploaded_file($a_upload_file, $file);
945  rename($a_upload_file, $file);
946  }
947 
952  public static function _lookupAbsolutePath ($obj_id, $a_version = null)
953  {
954  $file_storage = new ilFSStorageFile($obj_id);
956  $version_subdir = "";
957 
958  if (!is_numeric($a_version))
959  {
960  $a_version = ilObjFile::_lookupVersion ($obj_id);
961  }
962  $version_subdir = DIRECTORY_SEPARATOR.sprintf("%03d", $a_version);
963  return $file_storage->getAbsolutePath().$version_subdir.DIRECTORY_SEPARATOR.$filename;
964  }
965 
970  public function checkFileExtension($new_filename,$new_title)
971  {
972  include_once './Modules/File/classes/class.ilObjFileAccess.php';
973  $fileExtension = ilObjFileAccess::_getFileExtension($new_filename);
974  $titleExtension = ilObjFileAccess::_getFileExtension($new_title);
975  if ($titleExtension != $fileExtension && strlen($fileExtension) > 0)
976  {
977  // remove old extension
978  $pi = pathinfo($this->getFileName());
979  $suffix = $pi["extension"];
980  if ($suffix != "")
981  {
982  if (substr($new_title,
983  strlen($new_title) - strlen($suffix) - 1)
984  == ".".$suffix)
985  {
986  $new_title = substr($new_title, 0, strlen($new_title) - strlen($suffix) - 1);
987  }
988  }
989  $new_title .= '.'.$fileExtension;
990  }
991  return $new_title;
992  }
993 
994 
995 } // END class.ilObjFile
996 ?>