10 defined(
'JPATH_PLATFORM') or die;
12 jimport('joomla.filesystem.path');
32 public static function getExt($file)
34 $dot = strrpos($file,
'.') + 1;
36 return substr($file, $dot);
48 public static function stripExt($file)
50 return preg_replace(
'#\.[^.]*$#',
'', $file);
62 public static function makeSafe($file)
65 $file = rtrim($file,
'.');
67 $regex = array(
'#(\.){2,}#',
'#[^A-Za-z0-9\.\_\- ]#',
'#^\.#');
69 return trim(preg_replace($regex,
'', $file));
84 public static function copy($src, $dest, $path = null, $use_streams =
false)
94 if (!is_readable($src))
105 if (!$stream->copy($src, $dest))
118 if ($FTPOptions[
'enabled'] == 1)
121 $ftp =
JClientFtp::getInstance($FTPOptions[
'host'], $FTPOptions[
'port'], array(), $FTPOptions[
'user'], $FTPOptions[
'pass']);
124 if (!file_exists(dirname($dest)))
126 jimport(
'joomla.filesystem.folder');
131 $dest =
JPath::clean(str_replace(JPATH_ROOT, $FTPOptions[
'root'], $dest),
'/');
133 if (!$ftp->store($src, $dest))
143 if (!@ copy($src, $dest))
165 public static function delete($file)
179 if ($FTPOptions[
'enabled'] == 1)
182 $ftp =
JClientFtp::getInstance($FTPOptions[
'host'], $FTPOptions[
'port'], array(), $FTPOptions[
'user'], $FTPOptions[
'pass']);
185 foreach ($files as $file)
199 elseif ($FTPOptions[
'enabled'] == 1)
201 $file =
JPath::clean(str_replace(JPATH_ROOT, $FTPOptions[
'root'], $file),
'/');
203 if (!$ftp->delete($file))
212 $filename = basename($file);
234 public static function move($src, $dest, $path =
'', $use_streams =
false)
243 if (!is_readable($src))
246 return JText::_(
'JLIB_FILESYSTEM_CANNOT_FIND_SOURCE_FILE');
253 if (!$stream->move($src, $dest))
266 if ($FTPOptions[
'enabled'] == 1)
269 $ftp =
JClientFtp::getInstance($FTPOptions[
'host'], $FTPOptions[
'port'], array(), $FTPOptions[
'user'], $FTPOptions[
'pass']);
272 $src =
JPath::clean(str_replace(JPATH_ROOT, $FTPOptions[
'root'], $src),
'/');
273 $dest =
JPath::clean(str_replace(JPATH_ROOT, $FTPOptions[
'root'], $dest),
'/');
276 if (!$ftp->rename($src, $dest))
285 if (!@ rename($src, $dest))
311 public static function read($filename, $incpath =
false, $amount = 0, $chunksize = 8192, $offset = 0)
313 JLog::add(__METHOD__ .
' is deprecated. Use native file_get_contents() syntax.',
JLog::WARNING,
'deprecated');
317 if ($amount && $chunksize > $amount)
319 $chunksize = $amount;
322 if (
false === $fh = fopen($filename,
'rb', $incpath))
336 if ($fsize = @ filesize($filename))
338 if ($amount && $fsize > $amount)
340 $data = fread($fh, $amount);
344 $data = fread($fh, $fsize);
357 while (!feof($fh) && (!$amount || strlen($data) < $amount))
359 $data .= fread($fh, $chunksize);
379 public static function write($file, &$buffer, $use_streams =
false)
381 @set_time_limit(ini_get(
'max_execution_time'));
384 if (!file_exists(dirname($file)))
386 jimport(
'joomla.filesystem.folder');
395 $stream->set(
'chunksize', (1024 * 1024));
397 if (!$stream->writeFile($file, $buffer))
410 if ($FTPOptions[
'enabled'] == 1)
413 $ftp =
JClientFtp::getInstance($FTPOptions[
'host'], $FTPOptions[
'port'], array(), $FTPOptions[
'user'], $FTPOptions[
'pass']);
416 $file =
JPath::clean(str_replace(JPATH_ROOT, $FTPOptions[
'root'], $file),
'/');
417 $ret = $ftp->write($file, $buffer);
422 $ret = is_int(file_put_contents($file, $buffer)) ?
true :
false;
440 public static function upload($src, $dest, $use_streams =
false)
446 $baseDir = dirname($dest);
448 if (!file_exists($baseDir))
450 jimport(
'joomla.filesystem.folder');
458 if (!$stream->upload($src, $dest))
472 if ($FTPOptions[
'enabled'] == 1)
475 $ftp =
JClientFtp::getInstance($FTPOptions[
'host'], $FTPOptions[
'port'], array(), $FTPOptions[
'user'], $FTPOptions[
'pass']);
478 $dest =
JPath::clean(str_replace(JPATH_ROOT, $FTPOptions[
'root'], $dest),
'/');
481 if (is_uploaded_file($src) && $ftp->store($src, $dest))
493 if (is_writeable($baseDir) && move_uploaded_file($src, $dest))
524 public static function exists($file)
539 public static function getName($file)
544 $file = str_replace(
'\\',
'/', $file);
545 $slash = strrpos($file,
'/');
547 if ($slash !==
false)
550 return substr($file, $slash + 1);