Jump to content

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

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.