Babban matsalar da ke da alaƙa da loda fayil ɗin tace HTML shine ana iya wucewa cikin sauƙi. An tsara matatun HTML don toshe wasu nau'ikan fayiloli daga loda, amma ana iya kewaye su ta hanyar canza tsawo na fayil ko ta amfani da kayan aiki don gyara taken fayil. Wannan yana nufin cewa har yanzu ana iya loda fayilolin ƙeta, masu yuwuwar haifar da rashin tsaro da keta bayanai. Bugu da ƙari, masu tacewa na HTML ba su iya gano lambar qeta a cikin fayil ba, don haka ko da an katange fayil ɗin qeta daga yin loda, yana iya ƙunsar lambar mugunyar da za a iya aiwatar da ita akan sabar.
<form action="upload.php" method="post" enctype="multipart/form-data"> <input type="file" name="fileToUpload" id="fileToUpload" accept=".html"> <input type="submit" value="Upload HTML File" name="submit"> </form>
1. Wannan layin yana ƙirƙirar nau'i na HTML tare da sifa mai aiki da aka saita zuwa "upload.php" da kuma hanyar sifa da aka saita zuwa "post", da kuma saita sifa na enctype zuwa "multipart/form-data":
Tace da tabbatar da mahimmancin fayil
Tace da tabbatar da mahimmancin fayil a cikin HTML tsari ne na tabbatar da cewa fayilolin da ake buƙata kawai ana ɗora su zuwa shafin yanar gizon. Ana iya yin haka ta hanyar kafa dokoki da sigogi don nau'ikan fayilolin da za a iya lodawa, kamar girman fayil, nau'in, ko tsawo. Bugu da ƙari, ana iya amfani da siffofin HTML don inganta shigarwar mai amfani kafin a ƙaddamar da shi ga uwar garken. Wannan yana taimakawa tabbatar da cewa an karɓi ingantattun bayanai kawai kuma yana hana aiwatar da lambar qeta akan sabar. A ƙarshe, yana da mahimmanci a yi amfani da amintattun hanyoyi don loda fayiloli kamar amfani da ka'idojin HTTPS ko SFTP maimakon FTP.
Ta yaya zan taƙaita nau'ikan fayil a HTML
Ma'auni na HTML baya samar da hanya don taƙaita nau'ikan fayil lokacin amfani da wani kashi. Koyaya, zaku iya amfani da JavaScript don bincika nau'in fayil ɗin kafin a loda shi.
Don yin wannan, zaku iya amfani da FileReader API don karanta abubuwan da ke cikin fayil ɗin sannan ku duba nau'in sa. Idan ba ɗaya daga cikin nau'ikan da aka yarda ba, zaku iya hana yin loda shi ta hanyar kiran preventDefault() akan abin da ya faru ya shige cikin mai sarrafa canjin ku.
Hakanan zaka iya amfani da sifa na karɓar HTML5 akan naka kashi don tantance nau'ikan fayilolin da aka yarda. Wannan zai haifar da takamaiman akwatin maganganu na burauza ya bayyana lokacin da mai amfani yayi ƙoƙarin loda fayil ɗin da baya cikin ɗaya daga cikin sigar da aka karɓa.