您可以尝试替换
$arr[\'name\'] = $post_slug . \'-\' . $random_number . \'.jpg\';
使用
$arr[\'name\'] = $post_slug . \'-\' . $arr[\'name\'];
获取文件格式
[post_slug]-[original_filename].ext
.
更新:
以下是
$arr
具有文件名的图像的结构
car.png
:
Array
(
[name] => car.png
[type] => image/png
[tmp_name] => /tmp/phpJKhCwI
[error] => 0
[size] => 5868
)
获取
[post_slug].ext
格式,可以使用此格式:
$arr[\'name\'] = $post_slug . \'.\' . pathinfo( $arr[\'name\'], PATHINFO_EXTENSION );
当帖子标题为
My favorite car
它变成:
Array
(
[name] => my-favorite-car.png
[type] => image/png
[tmp_name] => /tmp/phpJKhCwI
[error] => 0
[size] => 5868
)
当使用相同的文件名上载多个图像时,上载的图像文件名将变为:
my-favorite-car.png (1. upload)
my-favorite-car1.png (2. upload)
my-favorite-car2.png (3. upload)
...