A cikin duniyar ci gaban yanar gizo, ɗayan ayyukan akai-akai ya haɗa da sarrafa fayiloli. Ko don bincika ko akwai fayil, karanta daga ciki, ko rubuta a ciki, fahimtar yadda ake aiki da fayiloli yana da mahimmanci. Laravel, fitaccen tsarin aikace-aikacen gidan yanar gizo tare da bayyananne, ƙayataccen tsarin aiki, na iya tabbatar da ƙarfi sosai wajen sarrafa ayyukan fayil, musamman lokacin aiki a cikin ingantaccen tsarin fayil ɗin sa. Wannan labarin yana mai da hankali kan yanayin gama gari a cikin Laravel: duba idan akwai fayil.
Yanzu, bari mu shiga cikin zuciyar al'amarin - bincika ko akwai fayil a Laravel.
<?php use IlluminateSupportFacadesStorage; $fileExists = Storage::disk('local')->exists('file.jpg'); ?>
Wannan ɓangaren snippet lambar hanya ce mai sauri da sauƙi don bincika ko akwai 'file.jpg' a cikin faifan ma'ajin ku na gida a Laravel. Idan fayil ɗin ya wanzu, $ fileExists zai zama gaskiya, in ba haka ba karya.
Fahimtar lambar
Bari mu rushe lambar kuma mu fahimci mafita sosai. Laravel yana ba da kayan aiki masu ƙarfi don yin hulɗa tare da tsarin fayil ɗin ku, har ma an saita shi don ba da damar jama'a, na gida, har ma da Amazon S3 amfani daga cikin akwatin.
use IlluminateSupportFacadesStorage;
Da farko, an shigo da facade na 'Ajiya'. Facade na 'Ajiya' na Laravel yana ba da dacewa API don yin hulɗa tare da tsarin fayil daban-daban.
$fileExists = Storage::disk('local')->exists('file.jpg');
Don bincika ko akwai fayil ɗin, ana kiran hanyar 'akwai' akan facade na'Ajiye'. Wannan yana tabbatar da kasancewar fayil ɗin a cikin faifan 'na gida' da aka keɓe. Wannan hanyar, 'akwai', tana tabbatar da kasancewar fayil ɗin ta hanyar mayar da 'gaskiya' idan akwai kuma 'ƙarya' idan akasin haka.
Tsarin Fayil na Laravel & Facade Adana
Fahimtar tsarin fayil ɗin Laravel shine mabuɗin wannan aiki. Laravel yana ba da damar fakitin 'Flysystem' PHP ta Frank de Jonge, ci gaba, ɗakin karatu na abstraction filesystem. Yana ba da tallafi don ɗimbin adaftar adaftar, gami da hanyoyin ajiya na gida da na tushen girgije.
Idan aka kalli facade na Adana, yana dawo da misalin 'IlluminateFilesystemFilesystemManager'. Wannan yana ba da damar sauƙi zuwa kowane faifan da aka saita. Fayilolin musamman na iya sarrafa ayyuka kamar 'disk('s3')' ko 'faifai ('na gida')' dangane da wurin ajiyar fayil ɗin ku.
A ƙarshe, lokacin da ake mu'amala da ayyukan fayil, yana da mahimmanci a magance yuwuwar kurakurai cikin alheri, kamar samar da martani masu dacewa lokacin da babu fayil ɗin ko ba za a iya buɗe shi ba saboda rashin isassun izini.
Makamantan Ayyukan Fayil na Laravel
Laravel yana ba da kewayon sauran ayyuka masu alaƙa da fayil waɗanda zasu iya zama fa'ida a lokuta daban-daban na amfani:
- sa: Wannan yana dawo da abubuwan da ke cikin fayil ɗin.
- sa: Wannan hanyar tana rubuta abubuwan da aka bayar cikin fayil ɗin.
- share: Ana amfani da wannan don share fayil ɗin.
Facade na 'Ajiye' na Laravel yana sauƙaƙa aiki tare da fayiloli a cikin aikace-aikacen ku, kuma fahimtar waɗannan ayyukan yana da mahimmanci don haɓaka aikace-aikace mai fa'ida. Ta wannan labarin, mun sami nasarar bincika yadda ake bincika ko akwai fayil a Laravel, tsarin fayil ɗin Laravel wanda ba a buɗe ba, kuma wasu daga cikin hanyoyin sarrafa fayil ɗin suna da amfani sosai.