basename() public static method

Extract the trailing name component from a file path.
public static basename ( string $path ) : string
$path string
return string
Example #1
0
 function replace($path)
 {
     $F = new File($path);
     $md5 = $F->md5();
     $this->path = appPATH . 'qg/file/' . $md5;
     $F->copy($this->path);
     $this->setVs(array('name' => $F->basename(), 'mime' => $F->mime(), 'text' => $F->getText(), 'md5' => $F->md5(), 'size' => $F->size()));
 }
Example #2
0
 public function addFile(File $file, $filename = null)
 {
     // sanitize filename
     if (!($filename = Sanitizer::filename($filename))) {
         $filename = String::random(8);
     }
     $realFile = new File($filename);
     // if file type is known, set new extension
     $newFilename = $realFile->basename(false) . '.' . $realFile->extension();
     // store files in flat hirarchy
     $file = $file->move(new Dir(STATIC_DIR . $this->path), $newFilename, true);
     $this->fromArray(array('filename' => $file->basename(), 'mime_type' => $file->mimeType()));
     return $this;
 }
 /**
  * Test basename
  *
  * @return void
  */
 public function testBasename()
 {
     $this->assertEquals(basename($this->original_path), $this->object->basename());
 }
Example #4
0
 /**
  * @param $path
  * @param $filename
  * @return static
  */
 public static function createFromFile($path, $filename)
 {
     $model = new static();
     return $model->create(['filename' => $filename, 'temp_filename' => \File::basename($path), 'file_type' => \File::mimeType($path)]);
 }
Example #5
0
 /**
  * Resize source image and save as target. If wxh is empty you can convert from one image type to another. 
  * Abort if w or h is greater than 2 * original size. Requires convert from ImageMagic.
  *
  * @param string $wxh (e.g. 140x140 or 140x or x140)
  * @param string $source
  * @param string $target (if empty overwrite source)
  */
 public static function resizeImage($wxh, $source, $target = '')
 {
     $info = File::imageInfo($source);
     $resize = '';
     if (!empty($wxh)) {
         list($w, $h) = explode('x', $wxh);
         if ($w < 0 || $w > 2 * $info['width']) {
             throw new Exception('invalid resize width', "{$w} not in ]0, 2 * " . $info['width'] . "]");
         }
         if ($h < 0 || $h > 2 * $info['height']) {
             throw new Exception('invalid resize height', "{$h} not in ]0, 2 * " . $info['height'] . "]");
         }
         $resize = "-resize '{$wxh}'";
     }
     if (empty($target)) {
         $suffix = File::suffix($source, true);
         $base = File::basename($source, true);
         $temp = dirname($source) . '/' . $base . '_' . $wxh . $suffix;
         if (File::exists($temp)) {
             throw new Exception('already resizing or resize failed', $temp);
         }
         \rkphplib\lib\execute("convert {$resize} '{$wxh}' '{$source}' '{$temp}'");
         File::move($temp, $source);
         $target = $source;
     } else {
         \rkphplib\lib\execute("convert {$resize} '{$wxh}' '{$source}' '{$target}'");
     }
     File::exists($target, true);
 }
Example #6
0
 /**
  * $file_pathが属するパッケージのパスを返す
  * @param $file_path ファイルパス
  * @return string
  */
 public static function module_root_path($file_path)
 {
     $package = File::dirname($file_path);
     while ($package !== null) {
         $package_class = File::basename($package);
         if ($package_class === null) {
             break;
         }
         if (ctype_upper($package_class[0]) && is_file($package . '/' . $package_class . '.php')) {
             return $package;
         }
         $package = File::dirname($package);
     }
     $file = new File($file_path);
     return substr($file->fullname(), 0, strlen($file->ext()) * -1);
 }