私はsubstrとstrrposでstrrchrPHP関数を使用して、次のようなフルパスの文字列でファイル名を検索していました。
/images/onepiece.jpgはonepiece.jpgを返します
しかし今、私は最後の「/」ではなく最後の次の「/」を見つける関数が必要です: /images/anime/onepiece.jpgはanime/onepiece.jpgまたは/anime/onepiece.jpgを返します そしてstrrchrとして-1はしませんうまくいかない、hehehe :)、どうすればそれを達成できますか?
[解決済み]@middaparkaと@ShaktiSinghが言ったようにPHPpathinfo()を使用して、MySQLデータベースから画像文字列を取得する方法を変更しました。私の当初の意図どおり、サブフォルダーを含めることができるようになりました。
<?php
/*
* pathinfo() parameters:
* PATHINFO_DIRNAME = 1
* PATHINFO_BASENAME = 2
* PATHINFO_EXTENSION = 4
* PATHINFO_FILENAME = 8
* */
$slash = '/';
$mainpath = 'store/image/';
$thumbspath = 'cache/';
$path = $imgsrow->photo; //gets the string containing the partial path and the name of the file from the database
$dirname = pathinfo($path, 1); //gets the partial directory string
$basename = pathinfo($path, 2); //gets the name of the file with the extension
$extension = pathinfo($path, 4); //gets the extension of the file
$filename = pathinfo($path, 8); //gets the name of the file
$dims = '-100x100.'; //string of size of the file to append to the file name
$image = $mainpath . $path; //mainpath + path is the full string for the original/full size file
$thumbs = $mainpath . $thumbspath . $dirname . $slash . $filename . $dims . $extension; //string to point to the thumb image generated from the full size file
?>
<img src="<?= $thumbs; ?>" width="100" height="100" alt="<?= $row->description; ?>" />
<br />
<img src="<?= $image; ?>" width="500" height="500" alt="<?= $row->description; ?>" />