ILIAS  Release_4_1_x_branch Revision 61804
 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 "./classes/class.ilObject.php";
5 include_once('Modules/File/classes/class.ilFSStorageFile.php');
6 
18 class ilObjFile extends ilObject
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 ilObjFile($a_id = 0,$a_call_by_reference = true)
36  {
37  $this->version = 0;
38  $this->type = "file";
39  $this->raise_upload_error = true;
40  $this->ilObject($a_id,$a_call_by_reference);
41 
42  if($this->getId())
43  {
44  $this->initFileStorage();
45  }
46  }
47 
53  function create($a_upload = false, $a_prevent_meta_data_creation = false)
54  {
55  $new_id = parent::create();
56 
57  //BEGIN WebDAV Move Property creation into a method of its own.
58  $this->createProperties($a_upload);
59  //END WebDAV Move Property creation into a method of its own.
60 
61  return $new_id;
62  }
63  //BEGIN WebDAV: Move Property creation into a method of its own.
71  function createProperties($a_upload = false, $a_prevent_meta_data_creation = false)
72  {
73  global $ilDB,$tree;
74 
75  // Create file directory
76  $this->initFileStorage();
77  $this->file_storage->create();
78 
79  if($a_upload)
80  {
81  return true;
82  }
83 
84  // not upload mode
85  require_once("classes/class.ilHistory.php");
86  ilHistory::_createEntry($this->getId(), "create", $this->getFileName().",1");
87  $this->addNewsNotification("file_created");
88 
89 
90  require_once("./Services/News/classes/class.ilNewsItem.php");
91  $default_visibility = ilNewsItem::_getDefaultVisibilityForRefId($_GET['ref_id']);
92  if ($default_visibility == "public")
93  {
94  ilBlockSetting::_write("news", "public_notifications",
95  1, 0, $this->getId());
96  }
97 
98  $q = "INSERT INTO file_data (file_id,file_name,file_type,file_size,version,f_mode) "
99  ."VALUES (".$ilDB->quote($this->getId() ,'integer').","
100  .$ilDB->quote($this->getFileName() ,'text').","
101  .$ilDB->quote($this->getFileType() ,'text').","
102  .$ilDB->quote((int) $this->getFileSize() ,'integer').","
103  .$ilDB->quote(1 ,'integer').",".$ilDB->quote($this->getMode() ,'text').")";
104  $res = $ilDB->manipulate($q);
105 
106  // no meta data handling for file list files
107  if ($this->getMode() != "filelist" && !$a_prevent_meta_data_creation)
108  {
109  $this->createMetaData();
110  }
111  }
112  //END WebDAV: Move Property creation into a method of its own.
113 
117  function createMetaData()
118  {
120 
121  // add technical section with file size and format
122  $md_obj =& new ilMD($this->getId(),0,$this->getType());
123  $technical = $md_obj->addTechnical();
124  $technical->setSize($this->getFileSize());
125  $technical->save();
126  $format = $technical->addFormat();
127  $format->setFormat($this->getFileType());
128  $format->save();
129  $technical->update();
130  }
131 
143  function MDUpdateListener($a_element)
144  {
145  // Check file extension
146  // Removing the file extension is not allowed
147  include_once 'Services/MetaData/classes/class.ilMD.php';
148  $md = new ilMD($this->getId(),0, $this->getType());
149  if(!is_object($md_gen = $md->getGeneral()))
150  {
151  return false;
152  }
153  $title = $this->checkFileExtension($this->getFileName(), $md_gen->getTitle());
154  $md_gen->setTitle($title);
155  $md_gen->update();
156 
157  // handling for general section
158  parent::MDUpdateListener($a_element);
159 
160  // handling for technical section
161  include_once 'Services/MetaData/classes/class.ilMD.php';
162 //echo "-".$a_element."-";
163  switch($a_element)
164  {
165  case 'Technical':
166 
167  // Update Format (size is not stored in db)
168  $md = new ilMD($this->getId(),0, $this->getType());
169  if(!is_object($md_technical = $md->getTechnical()))
170  {
171  return false;
172  }
173 
174  foreach($md_technical->getFormatIds() as $id)
175  {
176  $md_format = $md_technical->getFormat($id);
177  ilObjFile::_writeFileType($this->getId(),$md_format->getFormat());
178  $this->setFileType($md_format->getFormat());
179  break;
180  }
181 
182  break;
183 
184  default:
185  }
186  return true;
187  }
188 
189 
190  function getDirectory($a_version = 0)
191  {
192  $version_subdir = "";
193 
194  if ($a_version)
195  {
196  // BEGIN WebDAV Avoid double slash before version subdirectory
197  $version_subdir = sprintf("%03d", $a_version);
198  // END WebDAV Avoid double slash before version subdirectory
199  }
200 
201  if(!is_object($this->file_storage))
202  {
203  $this->initFileStorage();
204  }
205 
206  return $this->file_storage->getAbsolutePath().'/'.$version_subdir;
207  }
208 
209  function createDirectory()
210  {
212  }
213 
214  function raiseUploadError($a_raise = true)
215  {
216  $this->raise_upload_error = $a_raise;
217  }
218 
219  function getUploadFile($a_upload_file, $a_filename)
220  {
221  $this->setVersion($this->getVersion() + 1);
222 
223  if (@!is_dir($this->getDirectory($this->getVersion())))
224  {
226  }
227 
228  $file = $this->getDirectory($this->getVersion())."/".$a_filename;
229  //move_uploaded_file($a_upload_file, $file);
230  ilUtil::moveUploadedFile($a_upload_file, $a_filename, $file, $this->raise_upload_error);
231  }
232 
236  function replaceFile($a_upload_file, $a_filename)
237  {
238  $this->getUploadFile($a_upload_file, $a_filename);
239 
240  require_once("classes/class.ilHistory.php");
242  $this->getId(),
243  "replace",
244  $a_filename.",".$this->getVersion()
245  );
246  $this->setFilename($a_filename);
247  $this->addNewsNotification("file_updated");
248  }
249 
250 
251  public function addFileVersion($a_upload_file,$a_filename)
252  {
253  $this->getUploadFile($a_upload_file, $a_filename);
254 
255  require_once("classes/class.ilHistory.php");
257  $this->getId(),
258  "new_version",
259  $a_filename.",".$this->getVersion()
260  );
261  $this->setFilename($a_filename);
262  $this->addNewsNotification("file_updated");
263 
264  }
265 
266 
270  function copy($a_source,$a_destination)
271  {
272  return copy($a_source,$this->getDirectory()."/".$a_destination);
273  }
274 
279  {
280  ilUtil::delDir($this->getDirectory());
281  $this->createDirectory();
282  }
283 
284  public function deleteVersions()
285  {
286  global $ilDB;
287 
288  $ilDB->manipulate("UPDATE file_data SET version = 1 WHERE file_id = ".$ilDB->quote($this->getId() ,'integer'));
289  $this->setVersion(0);
290  $this->clearDataDirectory();
291 
292  require_once("classes/class.ilHistory.php");
294 
295  }
296 
300  function read()
301  {
302  global $ilDB;
303 
304  parent::read();
305 
306  $q = "SELECT * FROM file_data WHERE file_id = ".$ilDB->quote($this->getId() ,'integer');
307  $r = $this->ilias->db->query($q);
308  $row = $r->fetchRow(DB_FETCHMODE_OBJECT);
309 
310  $this->setFileName($row->file_name);
311  $this->setFileType($row->file_type);
312  $this->setFileSize($row->file_size);
313  $this->setVersion($row->version);
314  $this->setMode($row->f_mode);
315 
316  $this->initFileStorage();
317  }
318 
322  function update()
323  {
324  global $ilDB;
325 
326  // no meta data handling for file list files
327  if ($this->getMode() != "filelist")
328  {
329  $this->updateMetaData();
330  }
331  parent::update();
332 
333  global $ilLog;
334 
335  //$ilLog->write(__METHOD__.' File type: '.$this->getFileType());
336 
337  $q = "UPDATE file_data SET file_name = ".$ilDB->quote($this->getFileName() ,'text').
338  ", file_type = ".$ilDB->quote($this->getFiletype() ,'text')." ".
339  ", file_size = ".$ilDB->quote((int) $this->getFileSize() ,'integer')." ".
340  ", version = ".$ilDB->quote($this->getVersion() ,'integer')." ".
341  ", f_mode = ".$ilDB->quote($this->getMode() ,'text')." ".
342  "WHERE file_id = ".$ilDB->quote($this->getId() ,'integer');
343  $res = $ilDB->manipulate($q);
344 
345  return true;
346  }
347 
351  function updateMetaData()
352  {
354 
355  // add technical section with file size and format
356  $md_obj =& new ilMD($this->getId(),0,$this->getType());
357  if(!is_object($technical = $md_obj->getTechnical()))
358  {
359  $technical = $md_obj->addTechnical();
360  $technical->save();
361  }
362  $technical->setSize($this->getFileSize());
363 
364  $format_ids = $technical->getFormatIds();
365  if (count($format_ids) > 0)
366  {
367  $format = $technical->getFormat($format_ids[0]);
368  $format->setFormat($this->getFileType());
369  $format->update();
370  }
371  else
372  {
373  $format = $technical->addFormat();
374  $format->setFormat($this->getFileType());
375  $format->save();
376  }
377  $technical->update();
378  }
379 
383  function setFileName($a_name)
384  {
385  $this->filename = $a_name;
386  }
387 
388  function getFileName()
389  {
390  return $this->filename;
391  }
392 
393  function setFileType($a_type)
394  {
395  global $ilLog;
396 
397 
398  $this->filetype = $a_type;
399  }
400 
401  function getFileType()
402  {
403  return $this->filetype;
404  }
405 
406  function setFileSize($a_size)
407  {
408  $this->filesize = $a_size;
409  }
410 
411  function getFileSize()
412  {
413  return $this->filesize;
414  }
421  function getDiskUsage()
422  {
423  require_once("./Modules/File/classes/class.ilObjFileAccess.php");
424  return ilObjFileAccess::_lookupDiskUsage($this->id);
425  }
426 
427 
428  // END PATCH WebDAV Encapsulate file access in ilObjFile class.
429  function getFile($a_hist_entry_id = null)
430  {
431  if (is_null($a_hist_entry_id))
432  {
433  $file = $this->getDirectory($this->getVersion())."/".$this->getFileName();
434  }
435  else
436  {
437  require_once("classes/class.ilHistory.php");
438  $entry = ilHistory::_getEntryByHistoryID($a_hist_entry_id);
439 
440  if ($entry === false)
441  {
442  return false;
443  }
444 
445  $data = explode(",",$entry["info_params"]);
446 
447  // bugfix: first created file had no version number
448  // this is a workaround for all files created before the bug was fixed
449  if (empty($data[1]))
450  {
451  $data[1] = "1";
452  }
453 
454  $file = $this->getDirectory($data[1])."/".$data[0];
455  }
456  return $file;
457  }
458  // END PATCH WebDAV Encapsulate file access in ilObjFile class.
459 
460  function setVersion($a_version)
461  {
462  $this->version = $a_version;
463  }
464 
465  function getVersion()
466  {
467  return $this->version;
468  }
469 
475  function setMode($a_mode)
476  {
477  $this->mode = $a_mode;
478  }
479 
485  function getMode()
486  {
487  return $this->mode;
488  }
489 
490  function _writeFileType($a_id ,$a_format)
491  {
492  global $ilDB;
493 
494  $q = "UPDATE file_data SET ".
495  " file_type = ".$ilDB->quote($a_format ,'text').
496  " WHERE file_id = ".$ilDB->quote($a_id ,'integer');
497  $res = $ilDB->manipulate($q);
498 
499  }
500 
501  function _lookupFileName($a_id)
502  {
503  global $ilDB;
504 
505  $q = "SELECT * FROM file_data WHERE file_id = ".$ilDB->quote($a_id ,'integer');
506  $r = $ilDB->query($q);
507  $row = $r->fetchRow(DB_FETCHMODE_OBJECT);
508 
509  return ilUtil::stripSlashes($row->file_name);
510  }
511 
512 
514  function _lookupFileSize($a_id)
515  {
516  require_once("./Modules/File/classes/class.ilObjFileAccess.php");
517  return ilObjFileAccess::_lookupFileSize($a_id);
518  }
519 
523  function _lookupVersion($a_id)
524  {
525  require_once("./Modules/File/classes/class.ilObjFileAccess.php");
526  return ilObjFileAccess::_lookupVersion($a_id);
527  }
528 
532  function determineFileSize($a_hist_entry_id = null)
533  {
534  if (is_null($a_hist_entry_id))
535  {
536  $file = $this->getDirectory($this->getVersion())."/".$this->getFileName();
537  }
538  else
539  {
540  require_once("classes/class.ilHistory.php");
541  $entry = ilHistory::_getEntryByHistoryID($a_hist_entry_id);
542 
543  if ($entry === false)
544  {
545  return false;
546  }
547 
548  $data = explode(",",$entry["info_params"]);
549 
550  // bugfix: first created file had no version number
551  // this is a workaround for all files created before the bug was fixed
552  if (empty($data[1]))
553  {
554  $data[1] = "1";
555  }
556  $file = $this->getDirectory($data[1])."/".$data[0];
557  }
558  $this->setFileSize(filesize($file));
559  }
560 
561  function sendFile($a_hist_entry_id = null)
562  {
563  if (is_null($a_hist_entry_id))
564  {
565  $file = $this->getDirectory($this->getVersion())."/".$this->getFileName();
566 
567  // if not found lookup for file in file object's main directory for downward c ompability
568  if (@!is_file($file))
569  {
570  $file = $this->getDirectory()."/".$this->getFileName();
571  }
572  }
573  else
574  {
575  require_once("classes/class.ilHistory.php");
576  $entry = ilHistory::_getEntryByHistoryID($a_hist_entry_id);
577 
578  if ($entry === false)
579  {
580  echo "3";return false;
581  }
582 
583  $data = explode(",",$entry["info_params"]);
584 
585  // bugfix: first created file had no version number
586  // this is a workaround for all files created before the bug was fixed
587  if (empty($data[1]))
588  {
589  $data[1] = "1";
590  }
591 
592  $file = $this->getDirectory($data[1])."/".$data[0];
593 
594  // if not found lookup for file in file object's main directory for downward compability
595  if (@!is_file($file))
596  {
597  $file = $this->getDirectory()."/".$data[0];
598  }
599 
600  // BEGIN WebDAV removed duplicated code
601  // END WebDAV removed duplicated code
602  }
603 
604  if (@is_file($file))
605  {
606  global $ilClientIniFile;
607  if ($ilClientIniFile->readVariable('file_access','download_with_uploaded_filename') != '1')
608  {
609  ilUtil::deliverFile($file, $this->getTitle(), $this->guessFileType($file), $this->isInline());
610  }
611  else
612  {
613  ilUtil::deliverFile($file, basename($file), $this->guessFileType($file), $this->isInline());
614  }
615  return true;
616  }
617 
618  return false;
619  }
620 
621  // BEGIN WebDAV: Get file extension, determine if file is inline, guess file type.
626  function getFileExtension() {
627  require_once 'class.ilObjFileAccess.php';
629  }
635  function isInline() {
636  require_once 'class.ilObjFileAccess.php';
637  return ilObjFileAccess::_isFileInline($this->getTitle());
638  }
642  function isHidden() {
643  require_once 'class.ilObjFileAccess.php';
644  return ilObjFileAccess::_isFileHidden($this->getTitle());
645  }
646  // END WebDAV: Get file extension, determine if file is inline, guess file type.
647 
654  function guessFileType($a_file = "") {
655 
656  $path = pathinfo($a_file);
657  if ($path["extension"] != "")
658  {
659  $filename = $path["basename"];
660  }
661  else
662  {
663  $filename = "dummy.".$this->getFileExtension();
664  }
665  include_once("./Services/Utilities/classes/class.ilMimeTypeUtil.php");
666  $mime = ilMimeTypeUtil::getMimeType($a_file, $filename, $this->getFileType());
667  return $mime;
668 
669 /*
670  $fileType = $this->getFileType();
671  if (strlen($fileType) == 0) {
672  $fileType = 'application/octet-stream';
673  }
674 
675  // Firefox browser assigns 'application/x-pdf' to PDF files, but
676  // it can only handle them if the have the mime-type 'application/pdf'.
677  if ($fileType == 'application/x-pdf')
678  {
679  $fileType = 'application/pdf';
680  }
681 
682  if ($fileType == 'application/octet-stream')
683  {
684  $fileExtension = $this->getFileExtension();
685  $mimeArray = array(
686  'mpeg' => 'video/mpeg',
687  'mp3' => 'audio/mpeg',
688  'pdf' => 'application/pdf',
689  'gif' => 'image/gif',
690  'jpg' => 'image/jpg',
691  'png' => 'image/png',
692  'htm' => 'text/html',
693  'html' => 'text/html',
694  'wma' => 'video/x-ms-wma',
695  'wmv' => 'video/x-ms-wmv',
696  'swf' => 'application/x-shockwave-flash',
697  );
698  if (array_key_exists($fileExtension, $mimeArray))
699  {
700  $fileType = $mimeArray[$fileExtension];
701  }
702  }
703  return $fileType;
704 */
705  }
706 
715  public function cloneObject($a_target_id,$a_copy_id = 0)
716  {
717  global $ilDB;
718 
719  $new_obj = parent::cloneObject($a_target_id,$a_copy_id);
720  $new_obj->createDirectory();
721  $this->cloneMetaData($new_obj);
722 
723  // Copy all file versions
724  ilUtil::rCopy($this->getDirectory(),$new_obj->getDirectory());
725 
726  // object created now copy other settings
727  $query = "INSERT INTO file_data (file_id,file_name,file_type,file_size,version,f_mode) VALUES (".
728  $ilDB->quote($new_obj->getId() ,'integer').",".
729  $ilDB->quote($this->getFileName() ,'text').",".
730  $ilDB->quote($this->getFileType() ,'text').",".
731  $ilDB->quote((int) $this->getFileSize() ,'integer').", ".
732  $ilDB->quote($this->getVersion() ,'integer').", ".
733  $ilDB->quote($this->getMode() ,'text').")";
734  $res = $ilDB->manipulate($query);
735 
736  // copy history entries
737  require_once("classes/class.ilHistory.php");
738  ilHistory::_copyEntriesForObject($this->getId(),$new_obj->getId());
739 
740  // add news notification
741  $new_obj->addNewsNotification("file_created");
742 
743  return $new_obj;
744  }
745 
746 
753  function delete()
754  {
755  global $ilDB;
756 
757  // check, if file is used somewhere
758  $usages = $this->getUsages();
759 
760  if (count($usages) == 0)
761  {
762  // always call parent delete function first!!
763  if (!parent::delete())
764  {
765  return false;
766  }
767 
768  // delete file data entry
769  $q = "DELETE FROM file_data WHERE file_id = ".$ilDB->quote($this->getId() ,'integer');
770  $this->ilias->db->query($q);
771 
772  // delete history entries
773  require_once("classes/class.ilHistory.php");
775 
776  // delete entire directory and its content
777  if (@is_dir($this->getDirectory()))
778  {
779  ilUtil::delDir($this->getDirectory());
780  }
781 
782  // delete meta data
783  if ($this->getMode() != "filelist")
784  {
785  $this->deleteMetaData();
786  }
787 
788  return true;
789  }
790 
791  return false;
792  }
793 
801  function export($a_target_dir)
802  {
803  $subdir = "il_".IL_INST_ID."_file_".$this->getId();
804  ilUtil::makeDir($a_target_dir."/objects/".$subdir);
805 
806  $filedir = $this->getDirectory($this->getVersion());
807 
808  if (@!is_dir($filedir))
809  {
810  $filedir = $this->getDirectory();
811  }
812 
813  ilUtil::rCopy($filedir, $a_target_dir."/objects/".$subdir);
814  }
815 
819  function _deleteAllUsages($a_type, $a_id, $a_usage_hist_nr = 0)
820  {
821  global $ilDB;
822 
823  $ilDB->manipulate("DELETE FROM file_usage WHERE usage_type = ".
824  $ilDB->quote($a_type, "text").
825  " AND usage_id = ".$ilDB->quote((int) $a_id, "integer").
826  " AND usage_hist_nr = ".$ilDB->quote((int) $a_usage_hist_nr, "integer"));
827  }
828 
832  function _saveUsage($a_mob_id, $a_type, $a_id, $a_usage_hist_nr = 0)
833  {
834  global $ilDB;
835 
836  $ilDB->manipulate("DELETE FROM file_usage WHERE usage_type = ".
837  $ilDB->quote((string) $a_type, "text").
838  " AND usage_id = ".$ilDB->quote((int) $a_id, "integer").
839  " AND usage_hist_nr = ".$ilDB->quote((int) $a_usage_hist_nr, "integer").
840  " AND id = ".$ilDB->quote((int) $a_mob_id, "integer"));
841 
842  $ilDB->manipulate("INSERT INTO file_usage (id, usage_type, usage_id, usage_hist_nr) VALUES".
843  " (".$ilDB->quote((int) $a_mob_id, "integer").",".
844  $ilDB->quote((string) $a_type, "text").",".
845  $ilDB->quote((int) $a_id, "integer").",".
846  $ilDB->quote((int) $a_usage_hist_nr, "integer").")");
847  }
848 
852  function getUsages()
853  {
854  global $ilDB;
855 
856  // get usages in learning modules
857  $q = "SELECT * FROM file_usage WHERE id = ".$ilDB->quote($this->getId(), "integer");
858  $us_set = $ilDB->query($q);
859  $ret = array();
860  while($us_rec = $ilDB->fetchAssoc($us_set))
861  {
862  $ret[] = array("type" => $us_rec["usage_type"],
863  "id" => $us_rec["usage_id"],
864  "hist_nr" => $us_rec["usage_hist_nr"]);
865  }
866 
867  return $ret;
868  }
869 
878  function _getFilesOfObject($a_type, $a_id, $a_usage_hist_nr = 0)
879  {
880  global $ilDB;
881 
882  // get usages in learning modules
883  $q = "SELECT * FROM file_usage WHERE ".
884  "usage_id = ".$ilDB->quote((int) $a_id, "integer")." AND ".
885  "usage_type = ".$ilDB->quote((string) $a_type, "text")." AND ".
886  "usage_hist_nr = ".$ilDB->quote((int) $a_usage_hist_nr, "integer");
887  $file_set = $ilDB->query($q);
888  $ret = array();
889  while($file_rec = $ilDB->fetchAssoc($file_set))
890  {
891  $ret[$file_rec["id"]] = $file_rec["id"];
892  }
893 
894  return $ret;
895  }
896 
897  // TODO: What is this function good for??
898  function getXMLZip()
899  {
900  global $ilias;
901 
902  $zip = PATH_TO_ZIP;
903 
904  exec($zip.' '.ilUtil::escapeShellArg($this->getDirectory().'/'.$this->getFileName())." ".
905  ilUtil::escapeShellArg($this->getDirectory().'/'.'1.zip'));
906 
907  return $this->getDirectory().'/1.zip';
908  }
909 
910  function addNewsNotification($a_lang_var)
911  {
912  // BEGIN WebDAV Suppress news notification for hidden files
913  if ($this->isHidden()) {
914  return;
915  }
916  // END WebDAV Suppress news notification for hidden files
917 
918  global $ilUser;
919 
920  // Add Notification to news
921  include_once("./Services/News/classes/class.ilNewsItem.php");
922  include_once("./Modules/File/classes/class.ilObjFileAccess.php");
923  $news_item = new ilNewsItem();
924  $news_item->setContext($this->getId(), $this->getType());
925  $news_item->setPriority(NEWS_NOTICE);
926  $news_item->setTitle($a_lang_var);
927  $news_item->setContentIsLangVar(true);
928  if ($this->getDescription() != "")
929  {
930  $news_item->setContent(
931  "<p>".
932  $this->getDescription()."</p>");
933  }
934  $news_item->setUserId($ilUser->getId());
935  $news_item->setVisibility(NEWS_USERS);
936  $news_item->create();
937  }
938 
945  public function initFileStorage()
946  {
947  $this->file_storage = new ilFSStorageFile($this->getId());
948  return true;
949  }
959  function storeUnzipedFile($a_upload_file, $a_filename)
960  {
961  $this->setVersion($this->getVersion() + 1);
962 
963  if (@!is_dir($this->getDirectory($this->getVersion())))
964  {
965  ilUtil::makeDir($this->getDirectory($this->getVersion()));
966  }
967 
968  $file = $this->getDirectory($this->getVersion())."/".$a_filename;
969  //move_uploaded_file($a_upload_file, $file);
970  rename($a_upload_file, $file);
971  }
972 
977  public static function _lookupAbsolutePath ($obj_id, $a_version = null)
978  {
979  $file_storage = new ilFSStorageFile($obj_id);
981  $version_subdir = "";
982 
983  if (!is_numeric($a_version))
984  {
985  $a_version = ilObjFile::_lookupVersion ($obj_id);
986  }
987  $version_subdir = DIRECTORY_SEPARATOR.sprintf("%03d", $a_version);
988  return $file_storage->getAbsolutePath().$version_subdir.DIRECTORY_SEPARATOR.$filename;
989  }
990 
995  public function checkFileExtension($new_filename,$new_title)
996  {
997  include_once './Modules/File/classes/class.ilObjFileAccess.php';
998  $fileExtension = ilObjFileAccess::_getFileExtension($new_filename);
999  $titleExtension = ilObjFileAccess::_getFileExtension($new_title);
1000  if ($titleExtension != $fileExtension && strlen($fileExtension) > 0)
1001  {
1002  // remove old extension
1003  $pi = pathinfo($this->getFileName());
1004  $suffix = $pi["extension"];
1005  if ($suffix != "")
1006  {
1007  if (substr($new_title,
1008  strlen($new_title) - strlen($suffix) - 1)
1009  == ".".$suffix)
1010  {
1011  $new_title = substr($new_title, 0, strlen($new_title) - strlen($suffix) - 1);
1012  }
1013  }
1014  $new_title .= '.'.$fileExtension;
1015  }
1016  return $new_title;
1017  }
1018 
1019 
1020 } // END class.ilObjFile
1021 ?>