duminică, 10 ianuarie 2016

asdf


uf-v.1.0.php 30) { $error_message = 'The filename must have up to 30 characters.'; } else { #3.2 if (!preg_match('/^[a-z0-9._-]+\.[a-z]{2,4}$/i', $filename)) { $error_message = 'The filename isn\'t valid.'; } else { /* Verific daca fisierul este o imagine. Content-type-ul unei imaginii este o valoare de genul image/jpeg, image/pjpeg, image/gif, image/png. */ #3.3 if (!preg_match('/^image\//', $_FILES['userfile']['type'])) { $error_message = 'You are allowed to upload only images.'; } else { /* Functia PHP getimagesize() ma asigura 100% ca ceea ce urca utilizatorul e o imagine si nimic altceva. */ #3.4 $properties = getimagesize($_FILES['userfile']['tmp_name']); if ($properties == false) { $error_message = 'The file isn\'t an image.'; } else { /* Specific tipurile de imagini care pot fi urcate pe server. */ $allowed_extensions = array('.jpg', '.jpeg', '.gif', '.png'); $extension = substr($filename, strrpos($filename,'.'), 100); $extension = strtolower($extension); #3.5 if (!in_array($extension, $allowed_extensions)) { $error_message = 'You aren\'t allowed to upload '.$extension.' files.'; } else { /***/ /* Imaginea poate avea maxim 100 kb. */ #3.6 if (($_FILES['userfile']['size']/1024) > 100) { $error_message = 'The file can have up to 100 kb.'; } else { /* Restrictionez latimea pe care imaginea o poate avea. */ #3.7 if ($properties[0] > 100) { $error_message = 'The width must be up to 100px.'; } else { /* Restrictionez inaltimea pe care imaginea o poate avea. */ #3.8 if ($properties[1] > 100) { $error_message = 'The height must be up to 100px.'; } else { /* Daca folderul "images" nu exista pe server atunci il creez. */ #3.9 if (!is_dir('images')) { mkdir('images', 0777); } #3.10 if (file_exists('images/'.$filename)) { $error_message = 'The file '.$filename.' already exists.'; } else { /* Acum ca m-am asigurat ca ceea ce vrea utilizatorul sa urce este o imagine si nu altceva si acea imagine nu exista deja pe server, pot urca linistit imaginea de pe PC-ul utilizatorului pe serverul de hosting. Din motive de securitate schimb numele initial al imaginii utilizatorului. Noul nume este generat aleatoriu. */ #3.11 $alphabet = 'abcdefghijklmnoprqstuvxyz'; $new_fn = ''; for ($i = 0; $i < 10; $i++) { $new_fn .= substr($alphabet, rand(0,strlen($alphabet) - 1), 1); } #3.12 if (substr(sprintf('%o', fileperms('images')), -4) != 777) { $error_message = 'The folder has not the right permissions to read it.'; } else { $count = 0; $open = opendir ('images'); while ($image_name = readdir($open)) { //. reprezinta folderul curent iar .. reprezinta folderul anterior if ($image_name != '.' && $image_name != '..') { $image_extension = substr($image_name, strpos($image_name,'.'),100); $image_extension = strtolower($image_extension); if (in_array($image_extension,$allowed_extensions)) { $count++; } } } #3.13 if (move_uploaded_file($_FILES['userfile']['tmp_name'], 'images/'. ($count + 1).'_'.$new_fn.$extension)) { $confirmation = 'The file '.$filename. ' was succesfully uploaded.'; } else { $confirmation = 'Something is wrong with the server.'; } } } } } } /***/ } } } } } } } ?> How do I make a upload form?
'.$confirmation.'
'; ?> '.$error_message.''; ?>

- See more at: http://www.tutorialeonline.net/ro/article/cum-fac-un-formular-de-upload-in-php#sthash.C5L7pTjN.dpuf