Hey everyone,
I was wondering if anyone can help me work out how i can apply code to upload one image to multiple images.
I currently have the following code to upload images:
Models/Fileupload.class.php
<?php
class Fileupload{
protected $filename, $filetoupload;
public function __construct($filetoupload){
$this->filetoupload = $filetoupload;
}
public function upload(){
if(is_uploaded_file($_FILES[$this->filetoupload]['tmp_name']));{
if($_FILES[$this->filetoupload]['type'] == 'image/jpeg'
|| $_FILES[$this->filetoupload]['type'] == 'image/pjpeg'
|| $_FILES[$this->filetoupload]['type'] == 'image/png'){
$result = move_uploaded_file($_FILES[$this->filetoupload]['tmp_name'],
getcwd().'/items/'.$_FILES[$this->filetoupload]['name']);
} else {
$result = false;
}
}
return $result;
}
}
Then in my controller, when i want to upload an image i do something like this:
<?php
require_once('Models/Fileupload.class.php');
$fileupload = new Fileupload('filetoupload');
$result = $fileupload->upload();
So this executes the function and uploads the image, however i want to upload 3 images, in my View i have 3 fileuploads like so:
<input name="filetoupload" type="file" value="" id="filetoupload"/>
<input name="filetoupload2" type="file" value="" id="filetoupload2"/>
<input name="filetoupload3" type="file" value="" id="filetoupload3"/>
Now the first image uploads, but the second and third do not.
How can i change the structure of the function to accomplish this?
Thanks again