eT` Posted October 18, 2009 Report Share Posted October 18, 2009 Tātad izveidoju vienkāršu failu augšupielādes f-ju. Man vajadzētu, lai pārbauda failu paplašinājumu/us. Izveidoju, ka pārbauda vienu paplašinājumu, bet kā ir ar vairākiem? Man katru reizi veidot savu elseif :/ vai ir kāda iespēja kā visus paplašinājumus ievietot masīvā un tad pārbaudīt? mans pārbaudes kods: function findexts ($filename) { $filename = strtolower($filename) ; $exts = split("[/\\.]", $filename) ; $n = count($exts)-1; $exts = $exts[$n]; return $exts; } $ext = findexts ($_FILES['uploaded']['name']); if ($ext != rar) { echo "STFU!"; } Quote Link to comment Share on other sites More sharing options...
rausis Posted October 18, 2009 Report Share Posted October 18, 2009 saliec masīvā un ar in_array pārbaudi $allexts = array('rar', 'zip', 'txt'); if(!in_array($ext, $allexts)) { echo "STFU!"; } Quote Link to comment Share on other sites More sharing options...
eT` Posted October 18, 2009 Author Report Share Posted October 18, 2009 Paldies :) Quote Link to comment Share on other sites More sharing options...
marcis Posted October 18, 2009 Report Share Posted October 18, 2009 Un ir vienkāršāki (lasi - pareizāki, kas strādā arī tad, ja failam nav nosaukuma) veidi kā tikt pie paplašinājuma $ext = pathinfo($_FILES['uploaded']['name'], PATHINFO_EXTENSION); Quote Link to comment Share on other sites More sharing options...
briedis Posted October 18, 2009 Report Share Posted October 18, 2009 Un ir vienkāršāki (lasi - pareizāki, kas strādā arī tad, ja failam nav nosaukuma) veidi kā tikt pie paplašinājuma $ext = pathinfo($_FILES['uploaded']['name'], PATHINFO_EXTENSION); Tiešām? php.net: The following associative array elements are returned: dirname, basename, extension (if any), and filename. If options is used, this function will return a string if not all elements are requested. Quote Link to comment Share on other sites More sharing options...
marcis Posted October 18, 2009 Report Share Posted October 18, 2009 Nesapratu, ko tu centies pateikt... Quote Link to comment Share on other sites More sharing options...
briedis Posted October 18, 2009 Report Share Posted October 18, 2009 Man šis teikums likās aplams - "kas strādā arī tad, ja failam nav nosaukuma" Nevar taču dabūt paplašinājumu no faila nosaukuma, kur nemaz nav minēts paplašinājums... Quote Link to comment Share on other sites More sharing options...
marcis Posted October 18, 2009 Report Share Posted October 18, 2009 Pareizi, ka nevar. pathinfo() atgriezīs tukšu stringu, bet splitošana pa punktu atgriezīs paša faila nosaukumu. Quote Link to comment Share on other sites More sharing options...
briedis Posted October 18, 2009 Report Share Posted October 18, 2009 $ext = end(explode(".",$file_name)); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.