Jump to content

Please Help


haris244808

Recommended Posts

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;
					}	

}
}
}

Link to comment
https://forums.phpfreaks.com/topic/268515-please-help/
Share on other sites

  Quote

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>

Link to comment
https://forums.phpfreaks.com/topic/268515-please-help/#findComment-1378961
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.