Get Renamed File Names of JavaScript Forms in CodeIgniter - php

I have a multiple image upload form, and the following code is working well for uploading. I need to save file names to database to the database, but I cannot figure out how to do that properly.
uploadform.php:
echo form_open_multipart('gallery/upload');
<input type="file" name="photo" size="50" />
<input type="file" name="thumb" size="50" />
<input type="submit" value="Upload" />
</form>
gallery_model.php
function multiple_upload($upload_dir = 'uploads/', $config = array())
{
/* Upload */
$CI =& get_instance();
$files = array();
if(empty($config))
{
$config['upload_path'] = realpath($upload_dir);
$config['allowed_types'] = 'gif|jpg|jpeg|jpe|png';
$config['max_size'] = '2048';
}
$CI->load->library('upload', $config);
$errors = FALSE;
foreach($_FILES as $key => $value)
{
if( ! empty($value['name']))
{
if( ! $CI->upload->do_upload($key))
{
$data['upload_message'] = $CI->upload->display_errors(ERR_OPEN, ERR_CLOSE); // ERR_OPEN and ERR_CLOSE are error delimiters defined in a config file
$CI->load->vars($data);
$errors = TRUE;
}
else
{
// Build a file array from all uploaded files
$files[] = $CI->upload->data();
}
}
}
// There was errors, we have to delete the uploaded files
if($errors)
{
foreach($files as $key => $file)
{
#unlink($file['full_path']);
}
}
elseif(empty($files) AND empty($data['upload_message']))
{
$CI->lang->load('upload');
$data['upload_message'] = ERR_OPEN.$CI->lang->line('upload_no_file_selected').ERR_CLOSE;
$CI->load->vars($data);
}
else
{
return $files;
}
/* -------------------------------
Insert to database */
// problem is here, i need file names to add db.
// if there is already same names file at the folder, it rename file itself. so in such case, I need renamed file name :/
}
}

You should keep your model for database operations only. All the upload processing and file moving has to be done in the controller. The model has to insert the record about the photo in the database and that's about it.
And as a response to your question do a print_r($files) and see what it contains. It should have the original filenames. It'll probably be something like artmania said above: $files[0]['file_name']. You should be able to loop through your $files array with a foreach construct like this:
foreach($files as $file) {
$file_name = $file['file_name'];
}
You can get all the other data about the file in the same way. The CodeIgniter manual says about $this->upload->data():
This is a helper function that returns
an array containing all of the data
related to the file you uploaded. Here
is the array prototype:
Array
(
[file_name] => mypic.jpg
[file_type] => image/jpeg
[file_path] => /path/to/your/upload/
[full_path] => /path/to/your/upload/jpg.jpg
[raw_name] => mypic
[orig_name] => mypic.jpg
[file_ext] => .jpg
[file_size] => 22.2
[is_image] => 1
[image_width] => 800
[image_height] => 600
[image_type] => jpeg
[image_size_str] => width="800" height="200"
)
Fore more info check out the manual.

Related

PHP / HTML File Upload Not Recognizing Screenshot Images

I am building a file upload tool for my website and am running into a strange issue. The html input is set up to accept image/png, image/jpg, image/jpeg, .pdf files and it works fine when I am using it to upload PDFs or images that came from a camera or a design software.
However, when I upload an image (png) that was a screenshot taken on my Mac, the $_FILES has a value for the name attribute, but has no values for the tmp_name, type, error, size attributes. I've tried renaming the file to see if that was the issue, and that doesn't appear to be the problem either.
This is the output I get when I run print_r($_FILES):
Array ( [fileupload] => Array ( [name] => Array ( [0] => Screen Shot 2020-12-23 at 2.10.06 PM.png ) [type] => Array ( [0] => ) [tmp_name] => Array ( [0] => ) [error] => Array ( [0] => 1 ) [size] => Array ( [0] => 0 ) ) )
Warning: mime_content_type(): Empty filename or path in pro_testupload.php on line 87
Warning: getimagesize(): Filename cannot be empty in pro_testupload.php on line 91
Warning: mime_content_type(): Empty filename or path in pro_testupload.php on line 103
Does anyone have any idea about what is going on here? Below is my code:
HTML Code
<form method="POST" action="_process/pro_testupload.php" enctype="multipart/form-data">
<input type="file" id="fileupload" name="fileupload[]" accept="image/png, image/jpg, image/jpeg, .pdf" multiple required>
<button class="btn waves-effect black waves-light" type="submit">Upload</button>
</form>
PHP Code
// -----------------------------------------------------------------
// FILE FORMAT CHECKING FUNCTIONS
// -----------------------------------------------------------------
function check_image($filename) {
// Check mime type using PHPs own built in functions (as client side mime type is vulnerable to exploitation)
$mime_type = mime_content_type($filename);
$allowed_file_types = ['image/png', 'image/jpeg', 'image/jpg'];
// Check the file is actually an image
$check = getimagesize($filename);
// Perform all checks
if (in_array($mime_type, $allowed_file_types) && is_array($check) !== False) {
return True;
} else {
return False;
}
}
function check_pdf($filename) {
// Check mime type using PHPs own built in functions (as client side mime type is vulnerable to exploitation)
$mime_type = mime_content_type($filename);
$allowed_file_types = ['application/pdf'];
// Perform checks
if (in_array($mime_type, $allowed_file_types)) {
return True;
} else {
return False;
}
}
// -----------------------------------------------------------------
// CHECK FILES TO ENSURE THEY MEET REQUIREMENTS
// -----------------------------------------------------------------
if(!empty(array_filter($_FILES['fileupload']['name']))) {
foreach ($_FILES['fileupload']['tmp_name'] as $key => $value) {
if (!(check_image($_FILES['fileupload']['tmp_name'][$key]) || check_pdf($_FILES['fileupload']['tmp_name'][$key]))) {
echo ("The files do not meet the uploaded file requirements");
exit;
}
}
} else {
echo ("There were no files requested to be uploaded.");
exit;
}

CodeIgniter 3: "You have not specified any allowed file types. The filetype you are attempting to upload is not allowed."

I'm attempting to do a File Upload using the CodeIgniter "upload" library, but everytime I try to upload something I get this error:
"You have not specified any allowed file types. The filetype you are attempting to upload is not allowed."
I've searched and tried many solutions here on StackOverflow but none of them are working, here's my code:
views/screenshots.php
<form method="post" enctype="multipart/form-data" action="{baseurl}/upload/screenshot">
<input type="hidden" name="serverid" value="{id}" />
<label>Carica uno Screenshot</label>
<br />
<label class="custom-file" id="customFile" for="screenshot">
<input type="file" class="custom-file-input" id="screenshot" name="screenshot" aria-describedby="fileHelp">
<span class="custom-file-control form-control-file"></span>
</label>
<br />
<button type="submit" class="btn btn-secondary">Carica file</button>
</form>
config/upload.php
$config['allowed_types'] = '*';
$config['max_size'] = 1024 * 8;
$config['encrypt_name'] = TRUE;
controllers/upload.php
public function screenshot()
{
/* Upload library config */
$config['upload_path'] = './files/screenshots/';
$this->upload->initialize($config);
/* Upload and check if it's failed */
if (!$this->upload->do_upload('screenshot')) {
$error = array('error' => $this->upload->display_errors());
echo json_encode($error);
print_r($this->upload->data());
} else {
/* Making an array with all the data of the upload */
$upload_data = $this->upload->data();
/* Making an array to pass to the Screenshot_model */
$screenshot = array(
'id_server' => $this->input->post('serverid'),
'id_user' => $this->session->userdata('userid'),
'image_url' => $upload_data('file_name')
);
/* Saving the Screenshot info into the database */
$this->Screenshot_model->addScreen($screenshot);
/* Redirect to Server edit */
redirect('/screenshots/'.$screenshot['id_server']);
}
}
print_r($this->upload->data()) result
Array ( [file_name] => download.png [file_type] => image/png [file_path] => C:/xampp/htdocs/gameparade/files/screenshots/ [full_path] => C:/xampp/htdocs/gameparade/files/screenshots/download.png [raw_name] => download [orig_name] => [client_name] => download.png [file_ext] => .png [file_size] => 1806 [is_image] => 1 [image_width] => [image_height] => [image_type] => [image_size_str] => )
I'm autoloading the library. My version of CodeIgniter is 3.1.6. I've also tried to use form_open_multipart(); in the view, but nothing changes.
I'm using XAMPP 7.2.0 on Windows 10 (PHP Version 7.2.0).
The manual did not say '*' can be used for all types. So better to try to change this:
$config['allowed_types'] = '*';
to
$config['allowed_types'] = 'gif|jpg|png';
and then try it with one of the file type.
According to the official document ,
allowed_types default = None, options = None The mime types corresponding to the types of
files you allow to be uploaded. Usually the file extension can be used
as the mime type. Separate multiple types with a pipe.
Replace:
$this->upload->initialize($config);
with:
$this->upload->initialize($config, false);
From the docs (https://www.codeigniter.com/userguide3/libraries/file_uploading.html):
initialize([array $config = array()[, $reset = TRUE]])
Parameters:
$config (array) – Preferences
$reset (bool) – Whether to reset preferences (that are not provided in $config) to their defaults

how to insert multiple text box with file uploader values in mysql database?

i have multiple textbox with file uploader but i can't able to store the file in folder path. i want to add more fields for upload and store the files in the specific folder.
I tried everything. i have attached my code with this please look.
Sorry for my bad english.
PHP code for upload:
<?php if(isset($_FILES['attach'])){
$errors= array();
$file_name = $_FILES['attach']['name'];
$file_size =$_FILES['attach']['size'];
$file_tmp =$_FILES['attach']['tmp_name'];
$file_type=$_FILES['attach']['type'];
$file_ext=strtolower(end(explode('.',$_FILES['attach']['name'])));
$extensions= array("jpeg","jpg","png");
if(in_array($file_ext,$extensions)=== false){
$errors[]="extension not allowed, please choose a JPEG or PNG file.";
}
if($file_size < 2097152){
$errors[]='File size must be excately 2 MB';
}
if(empty($errors)==true){
move_uploaded_file($file_tmp,"images/".$file_name);
echo "Success";
}else{
print_r($errors);
}
}
?>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js" type = "text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
var maxField = 10; //Input fields increment limitation
var addButton = $('.add_button'); //Add button selector
var wrapper = $('.field_wrapper'); //Input field wrapper
var fieldHTML = '<div><input type="text" name="field_name[]" value=""/><input type="text" name="hint[]" value=""> <input type="file" name="attach[]" value=""><img src="remove-icon.png" alt="Remove"/></div>'; //New input field html
var x = 1; //Initial field counter is 1
$(addButton).click(function(){ //Once add button is clicked
if(x < maxField){ //Check maximum number of input fields
x++; //Increment field counter
$(wrapper).append(fieldHTML); // Add field html
}
});
$(wrapper).on('click', '.remove_button', function(e){ //Once remove button is clicked
e.preventDefault();
$(this).parent('div').remove(); //Remove field html
x--; //Decrement field counter
});
});
</script>
<form name="" action="" method="post" enctype="multipart/form-data">
<div class="field_wrapper" id="qus_box">
<div>
<input type="text" name="field_name[]" value=""/>
<input type="text" name="hint[]" value="">
<input type="file" name="attach[]" value="">
Add
<input type="submit" name="submit" value="SUBMIT"/>
</div>
</div>
</form>
You just do a foreach loop over the $_FILES array. This is a duplicate of this question and has been asked and answered many times over:
Multiple file upload in php
That being said, since it's been answered already and so I don't just regurgitate what's already out there, I will add a bit more to this answer. In this day and age, you can't just simply upload a file. Likely you will want to keep records of it in a database or show some stats on the view after the page reloads. To do that you need to use a class/method system (in my opinion) where you can actually do the upload but also get useful information back. A framework would take care of all this for you (and more!), but for the sake of this answer, here is a simple example, maybe it will give you ideas:
class Files
{
private $filesArr,
$destination,
$errors,
$success,
$full_path;
/*
** #description This will point the image uploads to a folder
** #param $dir [string] This is the directory where files will save
** #param $make [bool] This will instruct the method to make or not
** make a folder if not exists
*/
public function setDest($dir,$make = true)
{
if(!is_dir($dir)) {
if(!$make || ($make && !mkdir($dir,0755,true)))
throw new Exception('Directory does not exist');
}
$this->destination = $dir;
return $this;
}
/*
** #description This will upload the files and keep some records
** for reference after the fact
*/
public function saveFiles()
{
if(empty($this->filesArr)){
throw new Exception('No files to upload.');
return false;
}
foreach($this->filesArr as $file) {
$filename = $file['name'].'.'.$file['ext'];
if(!move_uploaded_file($file['tmp_name'],$this->destination.'/'.$filename))
throw new Exception('Could not save file "'.htmlspecialchars($filename).'" to folder.');
else {
$this->full_path[] = $this->destination.'/'.$filename;
$this->success[] = $filename;
}
}
}
/*
** #description This organized the files array and allows you to
** set different listeners
*/
public function organize($key)
{
foreach($_FILES[$key]['name'] as $num => $val) {
$ext = $this->getExt($val);
$size = $_FILES[$key]['size'][$num];
$name = pathinfo($val,PATHINFO_FILENAME);
if($_FILES[$key]['error'][$num] != 0) {
$this->errors[] = 'An error occurred: '.htmlspecialchars($name);
continue;
}
elseif(!$this->typeAllowed($ext)) {
$this->errors[] = 'File type not allowed ('.htmlspecialchars($ext).') :'.htmlspecialchars($name);
continue;
}
elseif(!$this->sizeAllowed($size)){
$this->errors[] = 'File too big: '.htmlspecialchars($name);
continue;
}
$this->filesArr[$num]['name'] = $name;
$this->filesArr[$num]['ext'] = $ext;
$this->filesArr[$num]['tmp_name'] = $_FILES[$key]['tmp_name'][$num];
$this->filesArr[$num]['size'] = $size;
$this->filesArr[$num]['tmp_name'] = $_FILES[$key]['tmp_name'][$num];
# I would put a path. I would remove directories outside
# of the root from the destination path. This way you
# can move a website to different web hosts and the
# path will still be good because it will be relative to
# the site root, not the server root. This is only important
# if you plan to store the path in a database...
$this->filesArr[$num]['full_path'] = $this->destination.'/'.$name.'.'.$ext;
}
return $this;
}
/*
** #description This just gives a summary of the actions taken in
** the event
*/
public function getStats()
{
$extsCnt = array();
$fileSum = 0;
if(!empty($this->filesArr)) {
foreach($this->filesArr as $files) {
$store['ext'][] = $files['ext'];
$store['size'][] = $files['size'];
}
if(!empty($store)){
$extsCnt = array_count_values($store['ext']);
$fileSum = array_sum($store['size']);
}
}
return array(
'success'=>(!empty($this->filesArr))? count($this->filesArr):0,
'errors'=>(!empty($this->errors))? count($this->errors):0,
'total_uploaded'=>$fileSum,
'extension_count'=>$extsCnt
);
}
public function toJson()
{
return json_encode($this->getFiles());
}
public function getFiles()
{
return $this->filesArr;
}
public function getErrors()
{
return $this->errors;
}
public function getSuccess()
{
return $this->success;
}
public function getPaths()
{
return $this->full_path;
}
# This method is a little weak. It needs to be more flexible
# Should be able to add/remove file types
public function typeAllowed($ext)
{
return in_array($ext,array("jpeg","jpg","png",'sql'));
}
public function getExt($filename)
{
return strtolower(pathinfo($filename,PATHINFO_EXTENSION));
}
public function sizeAllowed($size,$max = 2097152)
{
return ($size <= $max);
}
}
To apply to the page (the business logic) would be something like:
if(isset($_FILES['attach'])){
try {
# Create our instance
$fileManager = new Files();
# Set where we want to save files to
$fileManager
->setDest(__DIR__.'/file/to/save/here')
# Process what name from the form
->organize('attach')
# Do the upload
->saveFiles();
}
# Catch any errors thrown
catch(Exception $e) {
#You would probably want to display this in the view
# so output buffer works here
ob_start();
?>
<script>
alert('<?php echo $e->getMessage(); ?>');
</script>
<?php
$catch = ob_get_contents();
ob_end_clean();
}
}
# Here are some helpful data returns for DB storage or page view
if(isset($fileManager)) {
# Show errors
echo implode('<br />',$fileManager->getErrors()).'<br />';
# Show successful uploads
if(!empty($fileManager->getSuccess()))
echo 'Uploaded: '.implode('<br />Uploaded: ',$fileManager->getSuccess());
# Just some information that can be passed to other classes
print_r($fileManager->getFiles());
print_r($fileManager->getStats());
print_r($fileManager->toJson());
}
# Show alert in the view somewhere
if(isset($catch))
echo $catch;
The return shows something similar to this:
File type not allowed (pdf) : Filename1
Uploaded: Filename2.jpg
Uploaded: Filename3.png
Uploaded: Filename4.png
Array
(
[0] => Array
(
[name] => Filename2
[ext] => jpg
[tmp_name] => /datatmp/phpwDpP27
[size] => 17251
[full_path] => root/path/httpdocs/file/to/save/here/Filename2.jpg
)
[1] => Array
(
[name] => Filename3
[ext] => png
[tmp_name] => /datatmp/phpDXlSmH
[size] => 22636
[full_path] => root/path/httpdocs/file/to/save/here/Filename3.png
)
[2] => Array
(
[name] => Filename3
[ext] => png
[tmp_name] => /datatmp/phpSfE2Hg
[size] => 398811
[full_path] => root/path/httpdocs/file/to/save/here/Filename3.png
)
)
Array
(
[success] => 3
[errors] => 1
[total_uploaded] => 438698
[extension_count] => Array
(
[jpg] => 1
[png] => 2
)
)
[{"name":"Filename2","ext":"jpg","tmp_name":"\/datatmp\/phpwDpP27","size":17251},{"name":"Filename3","ext":"png","tmp_name":"\/datatmp\/phpDXlSmH","size":22636},{"name":"Filename4","ext":"png","tmp_name":"\/datatmp\/phpSfE2Hg","size":398811}]
Please use this code for multiple file upload:
<form name="" action="" method="post" enctype="multipart/form-data">
<div class="field_wrapper" id="qus_box">
<div>
<input type="text" name="field_name[]" value=""/>
<input type="text" name="hint[]" value="">
<input type="file" name="attach[]" value="" multiple="multiple">
Add
<input type="submit" name="submit" value="SUBMIT"/>
</div>
</div>
</form>
<?php
if(isset($_FILES['attach'])){
$errors= array();
$file_name = $_FILES['attach']['name'];
$file_size =$_FILES['attach']['size'];
$file_tmp =$_FILES['attach']['tmp_name'];
$file_type=$_FILES['attach']['type'];
$file_error = $_FILES['attach']['error'];
$extensions= array("jpeg","jpg","png");
foreach ($file_name as $f => $name) {
$file_ext=strtolower(end(explode('.',$name)));
if(in_array($file_ext,$extensions)=== false){
$errors[]="extension not allowed, please choose a JPEG or PNG file.";
}
if($file_size < 2097152){
$errors[]='File size must be excately 2 MB';
}
if(empty($errors)==true){
move_uploaded_file($file_tmp[$f],"images/".$file_name[$f]);
echo "Success";
}else{
print_r($errors);
}
}
?>
Please make sure that you have given permission to images folder.
For more details refer this link.

Store uploaded file data into array

I have the following situation:
I need to upload 3 files at once, when the user clicks to do so. There's the code I have in my view:
<?php echo form_open_multipart('uploads/do_upload', 'class="dropzone", id="dropzone-prod", data-nextFormExecDropzone="#dropzone-promo"');?>
<div class="fallback">
<input type="file" name="userfile" size="20" />
</div>
</form>
<?php echo form_open_multipart('uploads/do_upload', 'class="dropzone", id="dropzone-promo", data-nextFormExecDropzone="#dropzone-plan"');?>
<div class="fallback">
<input type="file" name="userfile" size="20" />
</div>
</form>
<?php echo form_open_multipart('uploads/do_upload', 'class="dropzone", id="dropzone-plan"');?>
<div class="fallback">
<input type="file" name="userfile" size="20" />
</div>
</form>
<div class="col-lg-4">
<button id="processQueue" class="btn btn-primary" type="button"><i class="fa fa-upload"></i>Start Upload</button>
</div>
When the user clicks in the button, I have a javascript code that sends each form the order I want it to.
In my controller, I have the following method (do_upload()):
function do_upload() {
//$filePath = $this->config->item('base_current_upload_url');
$filePath = APPPATH.'UPLOADS/';
$filePathAfterUploaded = $this->config->item('base_uploaded_url');
$config['upload_path'] = $filePath;
$config['allowed_types'] = '*';
$config['max_size'] = 1024 * 100;
$this->load->library('upload', $config);
//$this->load->library('csvreader');
//$filePathAfterUploaded = $this->config->item('base_uploaded_url');
//print_r($filePath); die();
$basefilepath = APPPATH.'UPLOADS/';
$this->load->model('uploads_m');
if ( ! $this->upload->do_upload('file')) {
$error = array('error' => $this->upload->display_errors());
print_r($error);
}
else {
$data = array('upload_data' => $this->upload->data());
print_r($data); die();
}
}
PROBLEM:
I need the 3 files to be uploaded. If only one is missing I can't proceed.
This way I'm doing, the function do_upload is being called during the upload of each file, so I need to find a way to identify that the 3 files were uploaded. (After that, I'll use mysql 'load data infile' to load data from these files into some tables, but I can only do this if the three were uploaded.
Can you help me finding a way to handle this situation?
The structure of the $data everytime do_uplaod is called is this:
Array
(
[upload_data] => Array
(
[file_name] => PROMOWEB111120131.txt
[file_type] => text/plain
[file_path] => C:/Program Files/EasyPHP-DevServer-13.1VC9/data/localweb/projects/integration/www/application/UPLOADS/
[full_path] => C:/Program Files/EasyPHP-DevServer-13.1VC9/data/localweb/projects/integration/www/application/UPLOADS/PROMOWEB111120131.txt
[raw_name] => PROMOWEB111120131
[orig_name] => PROMOWEB11112013.txt
[client_name] => PROMOWEB11112013.txt
[file_ext] => .txt
[file_size] => 2.67
[is_image] =>
[image_width] =>
[image_height] =>
[image_type] =>
[image_size_str] =>
)
)
If do_upload is a standalone function, then introduce a static variable that counts the number of calls.
function do_upload () {
static $count = 0;
// The rest of your function goes here
if (no_errors_occurred) {
static::$count++;
}
if ($count == 3) {
// This function has been called 3 times; trigger something here
}
}
Better yet, if it's in a class...
class MyClass {
protected static $data = array ();
// Other functions and properties
public function do_upload () {
// The rest of your function
if (no_errors_occurred) {
static::$data[] = array (
'upload_data' => array (
'file_name' => ...,
// Populate the data array
)
);
}
$this->do_mysql_load_data_infile();
}
protected function do_mysql_load_data_infile () {
if (count(static::$data) != 3) {
return false;
}
// Do MySQL load data infile
// Get information about file uploads by accessing the static::$data array
foreach (static::$data as $file) {
echo $file['upload_data']['file_name'];
}
}
}

PHP - Upload multiple images

I need to upload multiple images via form. I thought that I will do it with no problem, but I have one.
When I try to do foreach and get image by image it is not acting like I hoped it will.
HTML
<form method="post" action="" enctype="multipart/form-data" id="frmImgUpload">
<input name="fileImage[]" type="file" multiple="true" />
<br />
<input name="btnSubmit" type="submit" value="Upload" />
</form>
PHP
<?php
if ($_POST)
{
echo "<pre>";
foreach ($_FILES['fileImage'] as $file)
{
print_r($file);
die(); // I want it to print first image content and then die to test this out...
//imgUpload($file) - I already have working function that uploads one image
}
}
What I expected from it to print out first image, instead it prints names of all the images.
Example
Array
(
[0] => 002.jpg
[1] => 003.jpg
[2] => 004.jpg
[3] => 005.jpg
)
What I want it to output
Array
(
[name] => 002.jpg
[type] => image/jpeg
[tmp_name] => php68A5.tmp
[error] => 0
[size] => 359227
)
So how can I select image by image in the loop so I can upload them all?
Okey I found solution and this is how I did it, probably not the best way but it works.
foreach ($_FILES['fileImage']['name'] as $f)
{
$file['name'] = $_FILES['fileImage']['name'][$i];
$file['type'] = $_FILES['fileImage']['type'][$i];
$file['tmp_name'] = $_FILES['fileImage']['tmp_name'][$i];
$file['error'] = $_FILES['fileImage']['error'][$i];
$file['size'] = $_FILES['fileImage']['size'][$i];
imgUpload($file);
$i++;
}
that array is formed in another way
it's something line this:
array (
'name' => array (
[0] => 'yourimagename',
[1] => 'yourimagename2',
....
),
'tmp_file' => array (
....
that shoud do it :
foreach ($_FILES['fileImage']['name'] as $file)
{
print_r($file);
die(); // I want it to print first image content and then die to test this out...
//imgUpload($file) - I already have working function that uploads one image
}
You are basically asking of how to rebuild the $_FILES array to access subitems of them as one array.
$index = 0;
$field = 'fileImage';
$keys = array_keys($_FILES[$field]);
$file = array();
foreach($keys as $key)
{
$file[$key] = $_FILES[$field][$key][$index];
}
print_r($file);
change $index to the value you need to pick a specific file.

Categories