laravelÔõôÐÞ¸ÄͼƬÃû³Æ
laravelÊÇÒ»¿îÊ¢ÐеÄphp¿ò¼Ü£¬Ëü¾ßÓÐÓÅÑŵÄÓï·¨ºÍÇ¿Ê¢µÄ¹¦Ð§£¬¿ÉÓÃÓÚ¿ìËÙ¿ª·¢webÓ¦ÓóÌÐò¡£ÔÚlaravelÖУ¬´¦Öóͷ£ÎļþÉÏ´«ºÍͼÏñ´¦Öóͷ£Êdz£¼ûµÄʹÃü¡£ÔÚÉÏ´«Í¼Ïñʱ£¬Í¨³£ÐèÒªÐÞ¸ÄͼÏñµÄÎļþÃû£¬ÒÔ°ü¹ÜΨһÐÔºÍÒ×ÓÚÖÎÀí¡£
ÔÚLaravelÖÐÐÞ¸ÄͼÏñÎļþÃûÓжàÖÖÒªÁ죬ÏÂÃæÏÈÈÝÈýÖÖ³£ÓõÄÒªÁì¡£
ÒªÁìÒ»£ºÊ¹ÓÃPHPº¯Êýrename()
PHPÌṩÁËÒ»¸öÄÚÖú¯Êýrename()£¬¿ÉÒÔÖØÃüÃûÎļþ¡£LaravelÌṩÁ˼òÆӵķ½·¨À´Å²Óô˹¦Ð§¡£¿ÉÒÔʹÓÃÏÂÃæµÄ´úÂ뽫ÔÀ´µÄÎļþÃûÐÞ¸ÄΪеÄÎļþÃû£º
$old_name = public_path('uploads/old_name.jpg'); $new_name = public_path('uploads/new_name.jpg'); $renamed_file = rename($old_name, $new_name);
µÇ¼ºó¸´ÖÆ
ÉÏÃæµÄ´úÂëÖУ¬Ê¹ÓÃÁËpublic_path()º¯ÊýÀ´»ñÈ¡Îļþ·¾¶¡£ÈôÊÇÒªÉúÑÄÎļþµ½ÆäËûλÖã¬Ö»Ðè¼òÆӵظü¸Ä·¾¶¼´¿É¡£
ÒªÁì¶þ£ºÊ¹ÓÃLaravelÄÚÖú¯Êýmove()
LaravelÌṩÁËÒ»×éÀàËÆÓÚPHPº¯ÊýµÄÄÚÖú¯Êý£¬¿ÉÒÔÓÃÓÚÎļþÉÏ´«ºÍͼÏñ´¦Öóͷ£µÈʹÃü¡£ÆäÖÐÒ»¸öº¯ÊýÊÇmove()£¬¿ÉÒÔ½«ÎļþÒƶ¯µ½Ö¸¶¨Î»Öò¢ÖØÃüÃû¡£
ÀýÈ磬¼ÙÉèÄúµÄͼÏñÉÏ´«µ½public/uploads/Ŀ¼£¬²¢ÇÒÄúÏ£Íû½«ÆäÖØÃüÃûΪnew_name.jpg£¬¿ÉÒÔʹÓÃÒÔÏ´úÂ룺
$request->file('image')->move(public_path('uploads'), 'new_name.jpg');
µÇ¼ºó¸´ÖÆ
ÉÏÃæµÄ´úÂëÖУ¬Ê¹ÓÃÁË$request->file(‘image’)À´»ñÈ¡ÉÏ´«µÄÎļþ¹¤¾ß£¬È»ºóʹÓÃmove()º¯Êý½«ÎļþÒƶ¯µ½public/uploads/Ŀ¼²¢ÖØÃüÃûΪnew_name.jpg¡£ÈôÊÇÄúÏëÔÚÆäËûµØ·½ÉúÑÄÎļþ£¬Çë¸ü¸Ä·¾¶¼´¿É¡£
ÒªÁìÈý£ºÊ¹ÓÃStorageÃÅÃæºÍrename()º¯Êý
Laravel»¹ÌṩÁËÒ»¸öÃûΪStorageµÄÃÅÃ棬¿ÉÒÔÓÃÓÚ´¦Öóͷ£Îļþϵͳ²Ù×÷¡£ÔÚÕâÖÖÇéÐÎÏ£¬Äú¿ÉÒÔʹÓÃrename()º¯ÊýÀ´ÖØÃüÃûÎļþ¡£ÏÂÃæÊÇÒ»¸öʾÀý´úÂ룺
use IlluminateSupportFacadesStorage; Storage::rename('uploads/old_name.jpg', 'uploads/new_name.jpg');
µÇ¼ºó¸´ÖÆ
ÉÏÃæµÄ´úÂëÖУ¬Ê¹ÓÃÁËStorageÃÅÃæÀ´»á¼ûÎļþϵͳ£¬²¢Ê¹ÓÃrename()º¯Êý½«uploads/old_name.jpgÎļþÖØÃüÃûΪuploads/new_name.jpg¡£
×ܽá
LaravelÌṩÁ˶àÖÖÒªÁìÀ´ÐÞ¸ÄͼÏñÎļþÃû£¬ÆäÖаüÀ¨Ê¹ÓÃPHPº¯Êýrename()¡¢LaravelÄÚÖú¯Êýmove()ºÍStorageÃÅÃæºÍrename()º¯Êý¡£Ñ¡ÔñÄÄÖÖÒªÁìÈ¡¾öÓÚÄúµÄÏêϸÐèÇó¡£ÎÞÂÛÄúÑ¡ÔñÄÄÖÖÒªÁ죬½¨ÒéʹÓÃLaravelÌṩµÄAPI£¬¶ø²»ÊÇÖ±½ÓʹÓÃPHPº¯Êý£¬ÕâÑù¿ÉÒÔ¸üºÃµØÓëLaravelµÄÉú̬ϵͳ¾ÙÐн»»¥¡£
ÒÔÉϾÍÊÇlaravelÔõôÐÞ¸ÄͼƬÃû³ÆµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡