laravelÔõÑùдÈíÅþÁ¬
laravelÊÇÒ»¿î¼«ÊܽӴýµÄphp¿ò¼Ü£¬ÌṩÁËÐí¶àÀû±ãµÄ¹¦Ð§ºÍ¹¤¾ßÀ´¿ª·¢¸ßЧºÍ¹¦Ð§Ç¿Ê¢µÄÓ¦ÓóÌÐò¡£ÆäÖÐÖ®Ò»¾ÍÊÇÈíÅþÁ¬¡£ÈíÅþÁ¬¿ÉÒÔ×ÊÖúÎÒÃÇÔÚÏîÄ¿ÖÐÒýÓÃÆäËûÎļþ»òĿ¼£¬Ê¹µÃÏîÄ¿Ô½·¢½á¹¹»¯ºÍÒ×ÓÚÖÎÀí¡£ÔÚ±¾ÎÄÖУ¬ÎÒÃǽ«ÏÈÈÝÔõÑùÔÚlaravelÖÐдÈíÅþÁ¬¡£
ʲôÊÇÈíÅþÁ¬£¿
ÈíÅþÁ¬£¨Symbolic Link£©ÊÇÒ»ÖÖÎļþ£¬¿ÉÒÔÈÃÄ㽫һ¸öÎļþ»òĿ¼Á´½Óµ½ÁíÒ»¸öÎļþ»òĿ¼¡£ÈíÁ´½ÓÊÇÒ»¸öÖ¸ÏòÄ¿µÄÎļþ»òĿ¼µÄ¿ì½Ý·½·¨£¬²¢ÇÒ¿ÉÒÔ½ÚÔ¼¿Õ¼äºÍʱ¼ä¡£
ÔÚLaravelÖУ¬ÈíÅþÁ¬Í¨³£ÓÃÓÚÒÔÏÂÄ¿µÄ£º
¹²ÏíÎļþ»òĿ¼£»
ÒýÓù«¹²×ÊÔ´£¨ÈçͼƬ¡¢ÒôƵºÍÊÓƵ£©£»
°²ÅÅÇéÐΣ¬ÀýÈç°²ÅŲî±ðÇéÐÎʹÓòî±ðµÄÉèÖÃÎļþ¡£
ÔõÑù½¨ÉèÈíÅþÁ¬£¿
ÔÚLaravelÖУ¬Äã¿ÉÒÔʹÓÃArtisanÏÂÁîÐй¤¾ß½¨ÉèÈíÅþÁ¬¡£Ö¸¶¨ÒªÁ´½ÓµÄÔ´Îļþ»òĿ¼ºÍÁ´½ÓµÄÄ¿µÄ·¾¶£ºÀýÈ磬ÒÔÏÂÏÂÁ½¨ÉèÒ»¸öÈíÁ´½Ó£¬½«Ó¦ÓóÌÐòÖеĔpublic/images”Ŀ¼Á´½Óµ½”storage/app/public/images”Ŀ¼£º
php artisan storage:link
µÇ¼ºó¸´ÖÆ
Ö´ÐÐÕâ¸öÏÂÁîºó£¬Laravel»áΪÄ㽨ÉèÒ»¸ö”public/storage”µÄÈíÁ´½Ó£¬Õâ¸öÁ´½ÓÖ¸Ïò”storage/app/public”Ŀ¼¡£ÏÖÔÚ£¬Äã¾Í¿ÉÒÔʹÓÔpublic/storage”Ŀ¼À´»á¼û”storage/app/public”Ŀ¼ÖеÄÎļþ»òĿ¼ÁË¡£
ÔõÑùÔÚLaravelÖÐʹÓÃÈíÅþÁ¬£¿
LaravelÖеÄÈíÅþÁ¬¿ÉÒÔͨ¹ýÒÔÏ·½·¨À´Ê¹Óãº
ÔÚÄ£°åÖÐ
ÔÚLaravelµÄÊÓͼÖУ¬Äã¿ÉÒÔʹÓÃasset()º¯ÊýÀ´ÒýÓÃÈíÁ´½Ó¡£ÀýÈ磬ÒÔÏ´úÂë»á½«”public/storage”Ŀ¼ÏµĔimages/logo.png”ÎļþÒýÓõ½µÄÊÓͼÖУº
<img src="{{ asset('storage/images/logo.png') }}" alt="Logo">
µÇ¼ºó¸´ÖÆ
Õ⽫ÌìÉúÒÔÏÂHTML´úÂ룺
<img src="http://your-app.com/storage/images/logo.png" alt="Logo">
µÇ¼ºó¸´ÖÆ
ÔÚ¿ØÖÆÆ÷ÖÐ
³ýÁËÔÚÊÓͼÖУ¬Ä㻹¿ÉÒÔÔÚ¿ØÖÆÆ÷ÖÐʹÓÃÈíÁ´½Ó¡£ÒÔÏ´úÂë´ÓÈíÁ´½ÓĿ¼ÖмÓÔØÒôƵÎļþ£º
public function playAudio() { $audioPath = storage_path('app/public/audio/sample.mp3'); return response()->file($audioPath); }
µÇ¼ºó¸´ÖÆ
Õ⽫·µ»ØÒ»¸öÏìÓ¦¹¤¾ß£¬ÌáÐÑä¯ÀÀÆ÷Ïò”public/storage/audio/sample.mp3″ÌᳫÇëÇó£¬ÔÙ´Ó”storage/app/public/audio/sample.mp3″ÎļþÖзµ»ØÏìÓ¦¡£
ÔÚÉèÖÃÎļþÖÐ
ÔÚLaravelµÄÉèÖÃÎļþÖУ¬ÄãÒ²¿ÉÒÔʹÓÃÈíÁ´½Ó¡£ÒÔÏ´úÂëÑÝʾÔõÑùÔÚ”.env”ÎļþÖÐʹÓÃÈíÁ´½Ó£º
APP_NAME=Laravel APP_URL=http://your-app.com FILESYSTEM_DRIVER=local FILESYSTEM_CLOUD=public LOG_CHANNEL=stack LOG_LEVEL=debug APP_KEY= APP_DEBUG=true APP_LOG=daily APP_LOG_MAX_FILES=30 APP_LOG_LEVEL=debug DB_CONNECTION=mysql DB_HOST=localhost DB_PORT=3306 DB_DATABASE=laravel DB_USERNAME=root DB_PASSWORD= CACHE_DRIVER=file QUEUE_CONNECTION=sync SESSION_DRIVER=file SESSION_LIFETIME=120 # Use a symbolic link to store public files in PUBLIC_STORAGE_PATH=/var/www/html/your-app/storage/app/public
µÇ¼ºó¸´ÖÆ
Õ⽫¸æËßLaravelʹÓÔ/var/www/html/your-app/storage/app/public”Ŀ¼×÷Ϊ”public”Ŀ¼µÄÈíÁ´½Ó¡£ÕâÑù£¬Äã¾Í¿ÉÒÔ½«ËùÓй«¹²×ÊÔ´´æ´¢ÔÚ”storage/app/public”Ŀ¼ÖУ¬²¢´Ó”public”Ŀ¼Öлá¼ûËüÃÇ¡£
×ܽá
ÔÚLaravel¿ª·¢ÖУ¬ÈíÅþÁ¬ÊÇÒ»¸öºÜÊÇÓÐÓõŤ¾ß£¬Ëü¿ÉÒÔÀû±ãµØÓ³ÉäÒ»¸öÎļþ»òĿ¼µ½ÁíÒ»¸öµØ·½¡£ÔÚ±¾ÎÄÖУ¬ÎÒÃÇÒѾÏàʶÁËÔõÑùÔÚLaravelÖн¨É衢ʹÓúÍÉèÖÃÈíÅþÁ¬¡£Ï£ÍûÕâƪÎÄÕÂÄÜ×ÊÖúÄã¸üºÃµØÃ÷È·ÈíÅþÁ¬£¬²¢ÔÚLaravelµÄ¿ª·¢ÖÐÈ¡µÃ¸üºÃµÄЧ¹û¡£
ÒÔÉϾÍÊÇlaravelÔõÑùдÈíÅþÁ¬µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡