smagA-galva Posted March 8, 2007 Report Share Posted March 8, 2007 kas ir jamaina lai bilde saglabaajoties mapee uploads, nomaina sev nosaukumu. lai nesakristu ar kaadu citu bildi!!! if (is_uploaded_file ($_FILES['image1']['tmp_name'])) { if (move_uploaded_file($_FILES['image1']['tmp_name'], "./uploads/{$_FILES['image1']['name']}")){ echo '<p>Tikau augshuplādēts</p>'; } else { echo '<p><font color="red">Bilde netika aukshuplaadeeta!</font></p>'; $i=FALSE; } $i = $_FILES['image1']['name']; } else { $i = FALSE; } Link to comment Share on other sites More sharing options...
v3rb0 Posted March 8, 2007 Report Share Posted March 8, 2007 do { $filename = md5(microtime(true).$_FILES['image1']['name'].mt_rand(0,99999)); } while (file_exists('/uploads/'.$filename)); Link to comment Share on other sites More sharing options...
andrisp Posted March 8, 2007 Report Share Posted March 8, 2007 (edited) v3rb0, vai ir jēga saglabāt veco nosaukumu ? Ja nu tas satur kaut kādus nesakarīgus simbolus ? Ja vajag saglabāt paplašinājumu: preg_match('/(\.[a-z]+)$/i', $_FILES['image1']['name'], $m); do { $filename = substr(md5(time()),0,15).mt_rand(0,99999).$m[0]; } while (file_exists('/uploads/'.$filename)); Edited March 8, 2007 by andrisp Link to comment Share on other sites More sharing options...
v3rb0 Posted March 8, 2007 Report Share Posted March 8, 2007 tur viss iet ieks md5(), nekas nesaglabājas, vispār jau tas nav nekāds gudrais piemērs, tik parāda būtību - sagatavojam filenami, pārbaudam vai ir, ja ir taisam citu filenami. ja es taisītu priekš sevis tad atstātu esošo filenami/extensionu, ja vajadzīgs pirms extensiona liktu klāt kaut kādus cipariņus. .1,2,3,4,5 etc. vai arī bildes filename būtu kāds id no datubāzes. kā arī neliktu visus failus vienā folderī, bet pēc kaut kā (filenames/useriem/vēl kau kā) pa mapēm padalītu. Link to comment Share on other sites More sharing options...
andrisp Posted March 8, 2007 Report Share Posted March 8, 2007 Nepamanīju, ka viss iekš md5. Link to comment Share on other sites More sharing options...
smagA-galva Posted March 8, 2007 Author Report Share Posted March 8, 2007 v3rb0 - parādīsi ludzu skriptu kaa tu to labāk darītu... !!!$i - saglabaajas datubaazee!!!! Link to comment Share on other sites More sharing options...
andrisp Posted March 8, 2007 Report Share Posted March 8, 2007 (edited) Viņš tak tev parādīja. Padomā taču pats, ka ievietot to iekš sava skripta. Hints: iekš move_uploaded_file $_FILES['image1']['name'] vajag apmainīt ar uzģenerēto jauno $filename; OK, šādi aptuveni: http://paste.php.lv/5275 Edited March 8, 2007 by andrisp Link to comment Share on other sites More sharing options...
smagA-galva Posted March 10, 2007 Author Report Share Posted March 10, 2007 liels paldies!!! Link to comment Share on other sites More sharing options...
Recommended Posts