×ðÁú¿­Ê±¹ÙÍøµÇ¼

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ÔõôÐÞ¸ÄͼƬÃû³ÆµÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí £¬°æȨÕùÒéÓë±¾Õ¾ÎÞ¹Ø £¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±¹ÙÍøµÇ¼ÂËÓÍ»úÍø¹Ù·½Ì¬¶È £¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ £¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢ £¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢ £¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎå £¬9:30-18:30 £¬½ÚãåÈÕÐÝÏ¢

QR code
ÍøÕ¾µØͼ