Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $valid_formats = array("jpg", "JPG", "png", "PNG" , "bmp", "BMP");
- $max_file_size = 1024*6000; //60 000 kb - 6 mb
- $path = "../../../../img/final/img_recipes/"; //directory
- $count = 0;
- $uploaded_image_names = array(); //create a new array
- if(isset($_POST['files']) and $_SERVER['REQUEST_METHOD'] == "POST"){
- foreach ($_FILES['files']['name'] as $f => $img_name) {
- if ($_FILES['files']['error'][$f] == 4) {
- continue;
- }
- if ($_FILES['files']['error'][$f] == 0) {
- if ($_FILES['files']['size'][$f] > $max_file_size) {
- $message[] = "$img_name est trop lourde !";
- continue;
- }
- elseif( ! in_array(pathinfo($img_name, PATHINFO_EXTENSION), $valid_formats) ){
- $message[] = "$img_name est pas valide !";
- continue;
- }
- else{
- // Moved name and extension initialization to here.
- // Here is where you want to determine the actual filename
- $name = pathinfo($img_name, PATHINFO_FILENAME);
- $extension = pathinfo($img_name, PATHINFO_EXTENSION);
- $increment = 0;
- while(file_exists($path . $img_name)){
- $img_name = $name.$increment.'.'.$extension;
- $increment++;
- }
- if(move_uploaded_file($_FILES["files"]["tmp_name"][$f], $path.$img_name)) {
- $count++;
- //Store the uploaded filenames to array here
- $uploaded_image_names[] = "http://img.planeterecettes.com/img_recipes/".$img_name;
- }
- }
- }
- }
- }
- foreach ($uploaded_image_names as $uploaded_image_name){
- //store the $uploaded_image_name to db
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement