haris244808 Posted September 18, 2012 Share Posted September 18, 2012 Im trying to upload multiple pictures, but the code im using inserts only the last picture selected... can anyone tell me where i have my mistake pls here is the code that gets the file from form : if($placeGallery->upload($_FILES['pg_photo_name'])){//success //redirect to any page } else{//failure //bllallalla } } and here is the function im calling: public function upload($placeGalleryPhoto){ foreach($placeGalleryPhoto['name'] as $i => $name) { if($name[$i] == ""){ $this->errors[] = "No file was uploaded."; return false; } //Report what PHP says went wrong elseif($placeGalleryPhoto['error'][$i] != 0){ $this->errors[] = $this->file_errors[$placeGalleryPhoto['error'][$i]]; return false; } else{ $this->temp_path = $placeGalleryPhoto['tmp_name'][$i]; $this->extension = strtolower(strrchr($placeGalleryPhoto['name'][$i], '.')); $filename = //some random names; $this->photo_name = $filename . $this->extension; // Can't save without filename and temp location if(empty($this->photo_name) || empty($this->temp_path)){ $this->errors[] = "The file location was not available."; return false; } //target directory + picture name $uploadDir = $this->dir . $this->photo_name; if(move_uploaded_file($this->temp_path, $uploadDir)){ //sql query check } else{ $this->error[] = "Could not copy picture."; return false; } } } } Quote Link to comment https://forums.phpfreaks.com/topic/268515-please-help/ Share on other sites More sharing options...
Pikachu2000 Posted September 18, 2012 Share Posted September 18, 2012 Post the form. By the sounds of the symptoms the fields are probably not set up right. Quote Link to comment https://forums.phpfreaks.com/topic/268515-please-help/#findComment-1378951 Share on other sites More sharing options...
haris244808 Posted September 18, 2012 Author Share Posted September 18, 2012 Post the form. By the sounds of the symptoms the fields are probably not set up right. Thnx for replying Here is the form: <form action="page that have the function" method="post" enctype="multipart/form-data" > <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $placeGallery->max_photo_size; ?>" /> <input name="pg_photo_name[]" type="file" style="width:92%;" multiple /> <form> Quote Link to comment https://forums.phpfreaks.com/topic/268515-please-help/#findComment-1378961 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.