i have a project based on codeignitor , im facing a problem with uploading forms i cant attach more than one files i have an upload fields to attach user profile picture im trying to duplacate the filed to attach two or more files with no chance .
note i do all the changes in MVC files to the dublicated fields .
Here is the field code
<?php
if(isset($image))
echo "<div class='form-group has-error' >";
else
echo "<div class='form-group' >";
?>
<label for="qr" class="col-sm-2 control-label col-xs-8 col-md-2">
<?=$this->lang->line("student_passport_pic")?>
</label>
<div class="col-sm-4 col-xs-6 col-md-4">
<input class="form-control" id="uploadFile" placeholder="Choose File" disabled />
</div>
<div class="col-sm-2 col-xs-6 col-md-2">
<div class="fileUpload btn btn-success form-control">
<span class="fa fa-repeat"></span>
<span><?=$this->lang->line("upload")?></span>
<input id="uploadBtn" type="file" class="upload" name="image" />
</div>
</div>
<span class="col-sm-4 control-label col-xs-6 col-md-4">
<?php if(isset($image)) echo $image; ?>
</span>
</div>
please advice i need to upload too many files .
If you want multiple images from the same field. Make the input field name as an array.
For Ex : The first upload field should be like below
<input id="uploadBtn" type="file" class="upload" name="image[]"/>
Then, the input field which you are generating should also be of the same name
<input id="uploadBtn" type="file" class="upload" name="image[]"/>
and then in the controller where you are taking the POST value, you can take the values of the field using the $this->input->post('image') which will give you all the image names.
Related
I am having trouble with a file upload portion of a project. I have created the form with the inputs but when i try to "upload" the file it does not get posted into the $_FILES array. Code posted below. I have declared an enctype within the from tag but the file still does not get posted into the array it only shows Array()
here is my form code:
<?php
require("includes/application_top.php");
$pageTitle = "Add A Product";
require("includes/header.php");
print_r($_FILES);
?>
<div class="container-fluid py-4">
<div class="row ">
<div class="col">
<form method="POST" action="s.php" enctype="multipart/form-data">
<!-- Product Name input -->
<div class="form-outline">
<input type="text" id="ProductName" class="form-control" />
<label class="form-label" for="ProductName"> Product Name</label>
</div>
</div>
<div class="col">
<!-- Product Description input -->
<div class="form-outline">
<input type="text" id="ProductDesc" class="form-control" />
<label class="form-label" for="ProductDesc">Product Description</label>
</div>
</div>
</div>
<hr />
<div class="row">
<div class="col">
<!-- Product Price input -->
<div class="form-outline">
<input type="number" min="0.00" max="10000.00" step="0.01" id="ProductPrice" class="form-control" />
<label class="form-label" for="ProductPrice">Product Price </label>
</div>
</div>
<div class="col">
<!-- Img Upload input -->
<div class="form-outline input-group mb-3 ">
<input type="file" id="ImageUpload" class="form-control" />
<input type="submit" value="Upload" />
</div>
</div>
</div>
</form>
</div>
<?php
require("includes/footer.php")
?>
Any form field must have a name attribute in order to populate PHP's $_GET , $_POST or $_FILES superglobals after submitting the form.
$_GET and $_POST depend on the form method, and $_FILES is specific to file uploads (HTTP POST method only).
Your file input should then look like this:
<input type="file" id="ImageUpload" class="form-control" name="image_upload" />
Given the image_upload name I wrote, you should be able to get the file informations using $_FILES['image_upload].
Read about file uploads in the documentation: Handling file uploads.
You have to provide a name attribute to your fields, both $_POST and $_FILES work on the name attribute, not the ID. id is mostly used when you do something with the field using javascript, like when submitting the form with an ajax request.
In your case, you would need names:
<input type="file" id="ImageUpload" class="form-control" />
would become
<input type="file" name="ImageUpload" class="form-control" />
The same goes for your other input fields, you need a name attribute before you will see then in $_POST.
I'm developing an article-publishing utility and I'm using Froala's WYSIWYG textarea text editor that I included in a form, after storing the article's basic infos in the database, I want to store the uploaded images in the text editor on the server , the problem is when I use their php SDK to store images like mentioned in the documentation, I get this error: Fieldname is not correct. It must be: file
this is the html for the form:
<form method="post" class="mt-5" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>">
<div class="form-group row justify-content-center">
<div class="col-sm-9">
<label for="uname" style="color:#B1DDF1;"><b>Your Article's title</b></label>
<input type="text" id="focusedInput" class="form-control" name="title" placeholder="Make it creative!...">
</div>
</div>
<div class="form-group mt-2">
<label for="comment" style="color:#B1DDF1;"><b>Content goes here...</b></label>
<div id="editor"><textarea class="form-control" cols="200" rows="200"id='edit' name="file" placeholder="Type some text"><h1>This is a heading</h1>
<p>start writing your article here!</p></textarea></div>
</div>
<div class=" row mt-2 justify-content-center">
<input type="submit" class=" col-xs-6" value="Publish me!">
</div>
</form>
and here is a part of the PHP code:
$lastid=$conn->lastInsertId(); // get the new article's id for ressources management
$newarticfold="../LIGHT/articles_ressources/".$lastid;
try{
if(mkdir($newarticfold)){
require("wysiwygphp/lib/FroalaEditor.php");
$path="/Freelancing/CarthageP/test/LIGHT/articles_ressources/".$lastid."/"; //specifying the path from $_SERVER["DOCUMENT_ROOT"]
$resp=FroalaEditor_Image::upload($path);
echo("<div class='alert alert-success'>yaaay images got uploaded yaaaaay</div>");
}
}
I tried changing the name of the textarea to file, read the documentation many times and I tried to google the error message but I didn't find anything regarding it, what can be a possible cause for such a problem and how could it be fixed? Thank you very much in advance!
I have a working form that Inserts book entries to DB, it takes book title, isbn, book cover, etc.
I currently can upload the book cover and PDF version of the book without any issues, but the moment i try to upload a EPUB file instead of the PDF version, the FILES and POST arrive empty in the controller
-I have tried adding the mime types
'epub' => 'application/epub+zip',
//'epub' => array('application/octet-stream', 'application/epub+zip','application/smil+xml'),
The input works correctly because if i choose a PDF instead everything runs ok
// The form
<?php echo form_open_multipart(base_url().$this->uri->uri_string()); ?>
<div class="panel panel-default">
<div class="panel-heading"><h6 class="panel-title"><i class="icon-page-break"></i> </h6>
</div>
<div class="panel-body">
<h5>BOOK INFO</h5>
<div class="form-group">
<label>title:</label>
<input type="text" name="title" class="form-control" >
</div>
<div class="form-group">
<label>description:</label>
<textarea rows="5" cols="5" name="description" class="form-control"></textarea>
</div>
<div class="form-group">
<label>Cover:</label>
<input type="file" class="styled form-control" id="report-screenshot" name="userfile">
<span class="help-block">: gif, png, jpg</span>
</div>
<hr>
<h5>
FILES
</h5>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label>EPUB:</label>
<input type="file" class="styled form-control" id="epub_file" name="epub">
<span class="help-block">: .EPUB</span>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<label>PDF:</label>
<input type="file" class="styled form-control" id="pdf_file" name="pdf">
<span class="help-block">: .PDF</span>
</div>
</div>
</div>
<hr>
<div class="form-actions text-right">
<input type="submit" value="Add" class="btn btn-primary">
</div>
</div>
</div>
<?php echo form_close() ?>
// In the controller
var_dump($_FILES); // array (size=0)
var_dump($_POST); // array (size=0)
It was the post limit.
The POST limit was set to 9mb, the PDF size of the book was 8mb, the image was 500kb, the EPUB was 9.2 mbs. Thats why everything uploaded correctly if i omitted the EPUB, but if i tried uploading the EPUB even on its own it got deleted. Unfortunately post_max_size_limit didnt throw any warnings.
I have a form in HTML with some checkboxes and I want to send an email with the selected checkboxes in the body, the problem is that the "text" fields are passing to the PHP variables, but the checkboxes values are always set to uncheck when I test it on the PHP file:
HTML:
<div class="col-md-6">
<div class="c-checkbox-list">
<div class="c-checkbox">
<input type="checkbox" name="checkbox1citadina" id="checkbox1citadina" value="checkbox1citadina" class="form-control c-check" >
<label for="checkbox1citadina">
<span></span>
<span class="check"></span>
<span class="box"></span> Citadina
</label>
</div>
PHP:
$reservas_bicicletas = '';
if (isset($_POST['checkbox1citadina'])) {
$reservas_bicicletas .= "Citadina: checked\n";
} else {
$reservas_bicicletas .= "Citadina: unchecked\n";
}
echo $reservas_bicicletas;
$reservas_bicicletas always retrieves the else value.
Need help guys, thanks in advance.
remove c-check
<div class="col-md-6">
<div class="c-checkbox-list">
<div class="c-checkbox">
<input type="checkbox" name="checkbox1citadina" id="checkbox1citadina" value="checkbox1citadina" class="form-control " >
<label for="checkbox1citadina">
<span></span>
<span class="check"></span>
<span class="box"></span> Citadina</label>
</div>
Basically i have this (i shorted out the form because there are too many elements):
HTML:
<form name="quick_booking" id="quick_booking" method="post" action="assets/reserva-bicicletas.php">
<div class="col-md-6">
<div class="c-checkbox-list">
<div class="c-checkbox">
<input type="checkbox" name="checkbox1citadina" id="checkbox1citadina" value="checkbox1citadina" class="form-control " >
<label for="checkbox1citadina">
<span></span>
<span class="check"></span>
<span class="box"></span> Citadina</label>
</div>
<button type="submit" class="btn c-theme-btn c-btn-uppercase btn-lg c-btn-bold c-btn-square">Reservar</button>
</form>
Recently I need to use multiple input type file in one form. But when I post the form its returning null. Like I have nothing on $_POST. I have also add the enctype="multipart/form-data". I am stacked for last 2 days. Googled for many times. But still didn't get any solution. Please help me to out of this.
<form enctype="multipart/form-data" action="/admin/process_post/savepost" method="POST">
<div class="uk-grid uk-grid-small" data-uk-grid-margin="">
<div class="uk-width-medium-7-10">
<div class="md-card">
<div class="md-card-content">
<h3 class="heading_a uk-margin-medium-bottom">Add New Canvas</h3>
<div class="uk-grid" data-uk-grid-margin>
<div class="uk-width-medium-1-1">
<div class="uk-form-row">
<label>Post Title</label>
<input type="text" name="post_title" id="post_title" class="md-input" />
</div>
<div class="uk-form-row">
<label>Post Description</label>
<textarea id="post_desc" name="post_desc" cols="30" rows="20"></textarea>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="uk-width-medium-3-10">
<div class="md-card">
<div class="md-card-content">
<div class="uk-form-row">
<p>
<input type="checkbox" name="post_status" id="post_status" checked data-md-icheck />
<label for="post_status" class="inline-label">Post Status</label>
</p>
</div>
</div>
</div>
<div class="md-card">
<div class="md-card-content">
<div class="uk-form-row">
<label for="post_attachment" class="inline-label">Post Featured Image</label>
<input type="file" id="post_attachment" name="post_attachment">
</div>
</div>
</div>
<div class="md-card">
<div class="md-card-content">
<div class="uk-form-row">
<label for="result_img" class="inline-label">Post result Image</label>
<input type="file" id="result_img" name="result_img" multiple="multiple">
</div>
</div>
</div>
<div class="md-card">
<div class="md-card-content">
<div class="uk-form-row">
<button type="submit" class="uk-form-file md-btn md-btn-primary">Save Post</button>
</div>
</div>
</div>
</div>
</div>
</form>
I know this is a silly situation for a developer when they face problem like this.
Files can be gotten through $_FILES
When doing multiple uploads at same name, name it as array appending [] at end of name example: ( name="images[]" )
If upload continues to appear as empty, and you said in comment that with one file it's doing right, try to change at php.ini post_max_size and upload_max_filesize to a larger amount. Also check max_file_uploads - the number of files allowed for uploads per single request.
Your problem should be your form action, try to put an "/" on the end of it and see if it works:
<form enctype="multipart/form-data" action="/admin/process_post/savepost/" method="POST">
You need to change your file input name to an array
<input type="file" id="result_img" name="result_img[]">
Also try adding multiple
<input type="file" id="result_img" name="result_img[]" multiple>
To check for files you must use $_FILES instead of $_POST