laravelÔõôɾ³ýĿ¼ÖеÄͼƬ
laravel ÊÇÒ»¿îÊ¢ÐÐµÄ php ¿ò¼Ü£¬ËüÌṩÁËÐí¶àÓÐÓõĹ¦Ð§£¬ÉÁ¿ª·¢ÕßÔÚ¿ª·¢Àú³ÌÖÐÔ½·¢¸ßЧ¡¢±ã½Ý¡£ÔÚÐí¶àÓ¦Óÿª·¢ÖУ¬ÎÒÃÇÐèÒª¶ÔͼƬ¾ÙÐд¦Öóͷ££¬ÆäÖоÍÉæ¼°µ½Í¼Æ¬ÉÏ´«ºÍɾ³ý¡£±¾ÎĽ«ÏÈÈÝÔõÑùÔÚ laravel ¿ò¼ÜÖÐɾ³ýÖ¸¶¨Ä¿Â¼ÏµÄͼƬ¡£
Ò»¡¢LaravelµÄÎļþ´æ´¢·½·¨
ÔÚ Laravel ¿ò¼ÜÖУ¬ÎÒÃÇ¿ÉÒÔͨ¹ý´æ´¢ÒýÇæÀ´¾ÙÐÐÎļþµÄ´æ´¢ºÍ²Ù×÷¡£Laravel ×Ô´øÁ˶àÖÖ´æ´¢ÒýÇ棬°üÀ¨£º
ÍâµØ´æ´¢ÒýÇ棨Local£©
Amazon S3 ´æ´¢ÒýÇ棨S3£©
RackSpace ´æ´¢ÒýÇ棨Rackspace£©
FTP ´æ´¢ÒýÇ棨FTP£©
Aliyun OSS ´æ´¢ÒýÇ棨OSS£©
ÔÚ±¾ÎÄÖУ¬ÎÒÃÇÖ÷ÒªÏÈÈÝÔõÑùÔÚÍâµØ´æ´¢ÒýÇæÖÐɾ³ýĿ¼ÖеÄͼƬ¡£
¶þ¡¢É¾³ýÍâµØ´æ´¢ÒýÇæÖеÄͼƬ
Ê×ÏÈ£¬ÎÒÃÇÐèÒªÔÚ Laravel ÖлñÈ¡´æ´¢Â·¾¶¡£¿ÉÒÔͨ¹ý Storage::path() ÒªÁì»ñÈ¡£¬ÀýÈ磺
$path = Storage::path('uploads/images/');
µÇ¼ºó¸´ÖÆ
½ÓÏÂÀ´£¬ÐèҪȷ¶¨ÒªÉ¾³ýµÄͼƬÃû³Æ¡£¿ÉÒÔͨ¹ý File::glob() ÒªÁì»ñȡĿ¼ÏÂËùÓÐÎļþ£¬È»ºó¾ÙÐйýÂË»ñÈ¡Ö¸ÃüÃûÌõÄÎļþ£¬ÀýÈ磺
$files = File::glob($path . '*.jpg');
µÇ¼ºó¸´ÖÆ
È»ºó£¬ÎÒÃÇ¿ÉÒÔÑ»·±éÀúÕâЩͼƬ£¬Ê¹Óà File::delete() ÒªÁìɾ³ýÖ¸¶¨Í¼Æ¬£¬ÀýÈ磺
foreach ($files as $file) { File::delete($file); }
µÇ¼ºó¸´ÖÆ
Íê³ÉÒÔÉÏ°ì·¨ºó£¬ÎÒÃÇÒѾÍê³ÉÁËɾ³ýÖ¸¶¨Ä¿Â¼ÏÂËùÓÐÖ¸ÃüÃûÌõÄͼƬµÄ²Ù×÷¡£´úÂëʵÏÖÈçÏ£º
use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\Storage; $path = Storage::path('uploads/images/'); $files = File::glob($path . '*.jpg'); foreach ($files as $file) { File::delete($file); }
µÇ¼ºó¸´ÖÆ
Èý¡¢×ܽá
±¾ÎÄÏÈÈÝÁËÔÚ Laravel ¿ò¼ÜÖÐɾ³ýÖ¸¶¨Ä¿Â¼ÏµÄͼƬµÄÒªÁ졣ͨ¹ýʹÓà Laravel ÌṩµÄÎļþ²Ù×÷ÒªÁ죬ÎÒÃÇ¿ÉÒÔÈÝÒ×µØʵÏÖÎļþµÄɾ³ý²Ù×÷¡£Í¬Ê±£¬ÎÒÃÇÒ²¿ÉÒÔƾ֤ÏÖÕæÏàÐΣ¬Ñ¡ÔñÆäËû´æ´¢ÒýÇæÀ´¾ÙÐÐÎļþµÄ²Ù×÷¡£Ï£Íû±¾ÎĶԸ÷ÈËÓÐËù×ÊÖú¡£
ÒÔÉϾÍÊÇlaravelÔõôɾ³ýĿ¼ÖеÄͼƬµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡