How to upload files using backbone and rest api (codeignitier). following is my html form data:-
<form class="form-horizontal" id="upgrade_firmware" method="get" enctype="multipart/form-data">
<div class="control-group">
<label class="control-label muted">IMG</label>
<div class="controls">
<input type="file" id="fu-img" value="" name="fu-img" >
</div>
</div>
<div class="control-group">
<label class="control-label muted">MD5</label>
<div class="controls">
<input type="file" id="fu-md5" value="" name="fu-md5">
</div>
</div>
</form>
How can i upload this in my view files. if it is a form to create or delete i can use model.save in backbone and pass that in to rest api.But in this case this is a upload so how can i do it with backbone and rest api.
if i click upload button i can upload it to /home/upload directory and it should be a get call , why because i need to check the file is already there or not..if i call get i will get backend response as {"file":true} ,it means file already there so i exit.
if get call success i redirect to progress page,{"progress": 40%}
Is it possible to upload like this? upload file using get call and take appropriate response from backend? using backbone and rest api.
<?php defined('BASEPATH') OR exit('No direct script access allowed');
require(APPPATH.'/libraries/REST_Controller.php');
class FRM_Upload extends REST_Controller
{
function api_get()
{
//upload to /home/upload dir
$message = json_decode(file_get_contents("assets/json/firmware_progress.json"));
$this->response($message, 200);
}
}
Related
I am working on a project where I need to pass an ID to controller when someone clicks on the link, and open response in new tab.
I googled for solution on this, but couldn't find proper result. I also tried by sending data through URL in anchor tag, but then it gave an error of config.php file, so I reversed the code.
Currently I am using form tag to pass data. Can ye do this using PHP, or will we have to take help of jquery?
Here's View code:
<form class="form-horizontal" method="post" action='<?php echo base_url() . "home/edit_policy"; ?>'>
<div class="form-group">
<input type="hidden" class="form-control" id="polid" name="polid" value="<?php echo $ajax_view_pol_response[0]->polid; ?>">
<div class="col-sm-offset-3 col-sm-3">
<button class="btn btn-primary" id="editpolsubmit">Edit this Policy</button>
</div>
</div>
</font>
This code is from Controller:
public function edit_policy() {
$polid = $this->input->post('polid');
}
I want to transfer the "polid" from view to controller function using anchor tag.
All positive suggestions are appreciated.
I have a scenario where I have to make use of a form the old fashioned why like this;
<form action="{{ path('admin_app_address_import') }}" method="post" name="form_import">
<div class="form-group">
<label for="inputFile">File input</label>
<input type="file" id="inputFile" accept="text/csv" name="inputFile">
<p class="help-block">Select a CSV file to import.</p>
</div>
</form>
And then get the parameters from the form like this inside my action;
public function importAction(Request $request) {
$file = $request->files->get('inputFile');
var_dump($file);exit;
//...
}
But I keep on getting null. How can I get the file I try to read from? I don't need to store it in a database whatsoever, I just need to read the content to upload that to the database. I'm making a CSV import action, but I can't seem to get the file object.
When doing var_dump($request->request->all()); I do get the filename, but that won't work right?
When allowing file uploads, the encoding type of the form must be set to multipart/form-data:
<form ... enctype="multipart/form-data">
We are toying about with the Open Source Flamer app. We noticed that they are able to call a function in a separate class located in a different PHP file via a form POST request. Here is an example of how they do it:
<div id="upldate_location_service" class="div_service">
<form action="process.php/upDetails" method="post">
<h3>Update location :</h3>
<div class="form_row">
<div class="form_label">Session Token *: </div>
<div class="form_field"><input type="text" name="ent_sess_token" />name= "ent_sess_token"</div>
</div>
<div class="form_row">
<div class="form_label"> </div>
<div class="form_field"><input type="submit" name="ent_submit" value="Submit" /></div>
</div>
</form>
</div>
The function they are trying to access is UpdateLocation in the file Process.php. We have tried to recreate this process but it wont work. We can echo outside of our class, but for some reason we cant access or run any content in our process.php function.
Here is a copy of our process document:
class LegitAPI Extends API{
public function upDetails($args)
{
echo "Hello World";
}
}
Theoretically, when submitting the form on the index page, it should load process.php and then the method upDetails in the LegitAPI Class and display hello world. However, a blank page is instead being displayed.
Any ideas?
I have been working on a registration form for opencart for a while now. I think I am nearly there in how I have coded it.
However I just do not know where I am going wrong with it.
It is a standard form with text input fields and I just now need a file to be uploaded also on registration. I have added the upload button and added controller code just not working.
This is what I have so far:
Template file:
<legend>Documents</legend>
<p>Please upload as .pdf to ensure a smooth upload, thank you.</p>
<div class="form-group required">
<label class="col-sm-2 control-label" for="input-ast">AST:</label>
<div class="col-sm-10">
<input type="file" name="ast" value="<?php echo "AST"; ?>" placeholder="<?php echo $entry_ast; ?>" id="input-ast" class="form-control" />
</div>
</div>
Controller:
$data['ast'] = '';
$uploads_dir = 'tenant/upload/'; // set you upload path here
if (is_uploaded_file($this->request->files['ast']['tmp_name'])) {
move_uploaded_file($this->request->files['ast']['tmp_name'],$uploads_dir.$this->request->files['ast']['name']);
$data['ast'] = $this->request->files['ast']['name'];
}
Any input would be greatly appreciated
below is my 'mainview.php' view. from here iam attempting to submit and just open the next view which is called 'carerview.php'.
<form action="<?php echo base_url()?>login" method="post">
<div class="input-prepend">
<span class="add-on"><i class="icon-envelope"></i></span>
<input type="text" id="" name="" placeholder="your#email.com"></br></br>
<div class="input-prepend">
<span class="add-on"><i class="icon-lock"></i></span>
<input type="password" id="" name="" placeholder="Password"></br></br>
<button type="submit" class="btn btn-primary"><i class="icon-user icon-white"></i>Sign in</button>
</div>
</div>
</form>
Iam trying to submit this is giving me issues.The Index page loads which contains the above view. but when i submit . i get requested URL not found on this server
. then if i use the full url action="application/controllers/user/login" i get a forbidden, dont have permission to access it.
my method in my controller class is just to load the next view on submit so i dont think there is an issue there . below is the controller
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class User extends CI_Controller {
public function index()
{
if(!$this->isLoggedIn())
{
$this->load->view('mainview');
}
else
{
//do something
}
}
public function login()
{
$this->load->view('carerview');
}
public function isLoggedIn()
{
return false;
}
}
any help would be appreciated thanks.
if you didn't remove index.php from your URL and didn't set anything to base_url in configuration,try this
<?php echo base_url();?>index.php/user/login
localhost/your_app_folder/index.php/controller/action
Your form action is base_url(), which means is the application index route.
Try using form_open() (in the form_helper), which takes care of building the correct url:
<?php echo form_open('user/login');?>
... your form here
<?php echo form_close();?> // since I didn't see a close form tag in your form
Be careful of any routes that might intercept the request.
Alternatively, you could use site_url():
<form method="POST" action="<?php echo site_url('user/login');?>">