wordpress upload images in custom page - php

I have created a form for users in WordPress in a custom page, the code is below.
<div class="container" style="padding-top: 30px;width: 60%;">
<div id="FormBlock">
<form action="">
<div class="row form-group">
<div class="col-md-6">
<label for="lname">First Name:</label>
<input type="text" class="form-control" name="firstName" placeholder="Enter First Name..">
</div>
<div class="col-md-6">
<label for="lname">Last Name:</label>
<input type="text" class="form-control" name="lastName" placeholder="Enter Last Name..">
</div>
</div>
<div class="row form-group" style="margin-bottom: -8px;">
<div class="col-md-6">
<label for="email">Email</label>
<input type="email" class="form-control" name="email" placeholder="Enter Email..">
</div>
<div class="col-md-2">
<label for="cell">Phone:</label>
<?php echo countrySelector(); ?>
</div>
<div class="col-md-4">
<div class="input-group">
<label for=""> </label>
<input type="text" class="form-control" name="cellnumber" placeholder="Enter Phone Number..">
<label for=""> </label>
<span class="input-group-btn">
<button type="button" class="btn btn-basic" id="verify">Verify</button>
</span>
</div>
</div>
</div>
<div class="row form-group">
<div class="col-md-6">
<label for="Citizenship">Country of Citizenship</label>
<?php echo CountryNames("Citizenship","Citizenship"); ?>
</div>
<div class="col-md-6">
<label for="residence">Country of Residence</label>
<?php echo CountryNames("Residence","Residence"); ?>
</div>
</div>
<div class="row form-group">
<div class="col-md-12">
<label for="address">Residential Address</label>
<input type="text" class="form-control" name="address" placeholder="Enter your address..">
</div>
</div>
<div class="row form-group">
<div class="col-md-12">
<label for="ec2wallet">EC2 Wallet Address</label>
<input type="text" class="form-control" name="ec2wallet" placeholder="Enter your EC2 Wallet address..">
</div>
</div>
<div class="row">
<div class="col-md-12">
<label for="Upload">Upload your documents</label>
</div>
</div>
<div class="row form-group">
<div class="col-md-6">
<input type="file" name="identity" id="identity" class="form-control">
<label for="identity"><small>Upload proof of identity (Passport, Driver’s License, National Identification)</small></label>
</div>
<div class="col-md-6">
<input type="file" name="selfie" id="selfie" class="form-control">
<label for="selfie"><small>Take Selfie or Upload front facing picture</small></label>
</div>
</div>
<div class="row form-group">
<div class="col-md-12">
<input type="file" name="residenceID" id="residenceID" class="form-control">
<label for="residenceID"><small>Upload proof of residence (ID Card containing your address or utility bill, credit card statement, bank statement or tax bill dated within last 3 months).</small></label>
</div>
</div>
</form>
</div>
</div>
now I have three fields in which user have to upload documents/pics and I want to use WordPress proper method to upload media in which WordPress create database entries and their metadata etc.. and also if an image is an upload then WordPress creates it multiple sizes like a thumbnail or anything like that.
here is a view of my form.
Form View
can anyone help me or suggest me how can i do that?
I tried using ajax uploader or jquery uploading method, but there I have to do many things myself like making db entries. is there any proper method I have to follow?

using ajax call you need to create function in functions.php file.
your ajax call like:
$("#YourButtnID").click(function(){
var firstname = $('#fname').val();
// get all the fields (input) like this..
// and now for all the input type files.
var identity = jQuery('#identity').prop('files')[0];
var residence = jQuery('#residenceID').prop('files')[0];
var selfie = jQuery('#selfie').prop('files')[0];
//creating formData and inserting data into it
var formData = new FormData();
//action -> this will be your function name in functions.php
formData.append('action','your_custom_function');
//now all the data .. appending
formData.append('fname',firstname);
//Your images
formData.append('identity', identity);
formData.append('residence', residence);
formData.append('selfie', selfie);
$.ajax({
type: "POST",
url: ajaxurl,
contentType: false,
processData: false,
data: formData,
dataType: "JSON",
success:function(data){
if(data['status']){
//All went well
}else{
// something went wrong
},
error:function(err){
// You might not have caught any exception
}
});
and now in your functions.php file, create function to get all this done
<?php
function your_custom_function(){
// initial response is false by default
$response = array ('status'=>false,'msg'=>'invalid code');
// you can have server side validation here if you want
// i.e. if(!$_REQUEST['fname']) this means if this field is not sent.. then return relevant response
if (!function_exists('wp_handle_upload')) {
require_once(ABSPATH . 'wp-admin/includes/file.php');
}
$yourDBTable = $wpdb->prefix.'yourDBTable';
$uploadedfile = $_FILES['identity'];
$upload_overrides = array('test_form' => false);
$movefile = wp_handle_upload($uploadedfile, $upload_overrides);
//after uploading to uploads DIR you will get url of your image here
$id_url = $movefile['url'];
$uploadedfile = $_FILES['residence'];
$upload_overrides = array('test_form' => false);
$movefile = wp_handle_upload($uploadedfile, $upload_overrides);
$resid_url = $movefile['url'];
$uploadedfile = $_FILES['selfie'];
$upload_overrides = array('test_form' => false);
$movefile = wp_handle_upload($uploadedfile, $upload_overrides);
$selfie_url = $movefile['url'];
$user_data = array(
'fname' => $_REQUEST['fname'],
'photo_identity' => $id_url,
'photo_selfie' => $selfie_url,
'photo_residence' => $resid_url
);
try {
$result = $wpdb->insert($yourDBTable,$user_data);
$response['status']=true;
} catch (Exception $e) {
$response['msg']="Something went wrong";
}
echo json_encode($response);
wp_die();
}

Related

API "POST" shows successful but won't reflect changes on database

I have a basic web application that has been coded in php.
The app carries out CRUD operations by making use of an API made through PHP. When I try to use my update.php API endpoint, I get a successful response but no changes reflect in db.
Project Structure
Project_Structure
update.php in api/mailbox
<?php
// include database and object files
include_once '../config/database.php';
include_once '../objects/mailbox.php';
// get database connection
$database = new Database();
$db = $database->getConnection();
// prepare mailbox object
$mailbox = new Mailbox($db);
//For diagnostics
$data = json_decode(file_get_contents('php://input'), true);
print_r($data);
echo $data[""];
// set ID property of product to be edited
$mailbox_id->mailbox_id = $data->mailbox_id;
// set mailbox property values
$mailbox->username = $_POST['username'];
$mailbox->password = base64_encode($_POST['password']);
$mailbox->name = $_POST['name'];
$mailbox->quota = $_POST['quota'];
$mailbox->modified = date('Y-m-d H:i:s');
$mailbox->active = $_POST['active'];
$mailbox->mailbox_id = $_POST['mailbox_id'];
// create the mailbox
if($mailbox->update()){
$mailbox_arr=array(
"status" => true,
"message" => "Successfully Updated Mailbox"
);
}
else{
$mailbox_arr=array(
"status" => false,
"message" => "Mailbox already exists!"
);
}
print_r(json_encode($mailbox_arr));
?>
mailbox.php(in objects folder)
// update mailbox
function update(){
$query = "UPDATE
". $this->table_name ."
SET
username='".$this->username."', password='".$this->password."', name='".$this->name."', quota='".$this->quota."', modified='".$this->modified."', active='".$this->active."'
WHERE
mailbox_id= '".$this->mailbox_id."'";
// prepare query
$stmt = $this->conn->prepare($query);
// execute query
if($stmt->execute()){
return true;
}
return false;
}
update.php (The rendered page, on clicking update, the error is: **Mailbox already exists)**
<?php
$content = '<div class="container"
<div class="row">
<!-- left column -->
<div class="col-md-12">
<!-- general form elements -->
<div class="box box-primary">
<div class="box-header with-border">
<h3 class="box-title">Update Mailbox</h3>
</div>
<!-- /.box-header -->
<!-- form start -->
<form role="form">
<div class="box-body">
<div class="form-group">
<div class="form-group">
<label for="exampleMBID1">Mailbox ID</label>
<input type="text" class="form-control" id="mailbox_id" placeholder="Mailbox ID" disabled>
</div>
<label for="exampleInputUserName1">User Name</label>
<input type="text" class="form-control" id="username" placeholder="Enter Username e.g jsmith">
</div>
<div class="form-group">
<label for="exampleInputPassword1">Password</label>
<input type="password" class="form-control" id="password" placeholder="Enter Password">
</div>
<div class="form-group">
<label for="exampleInputName1">Name</label>
<input type="text" class="form-control" id="name" placeholder="Name of User">
</div>
<div class="form-group">
<label for="exampleInputMaildir1">Maildir</label>
<input type="text" class="form-control" id="maildir" placeholder="Enter Maildir" disabled>
</div>
<div class="form-group">
<label for="exampleInputQuota1">Quota (0=Unlimited)</label>
<input type="text" class="form-control" id="quota" placeholder="Enter Quota">
</div>
<div class="form-group">
<label for="examplelocalpart1">Local Part</label>
<input type="text" class="form-control" id="local_part" placeholder="localpart" disabled>
</div>
<div class="form-group">
<label for="exampledomain1">Domain</label>
<input type="text" class="form-control" id="domain" placeholder="domain" disabled>
</div>
<div class="form-group">
<label for="examplecreated1">Created</label>
<input type="text" class="form-control" id="created" placeholder="Created" disabled>
</div>
<div class="form-group">
<label for="examplemodified1">Modified</label>
<input type="text" class="form-control" id="modified" placeholder="Modified">
</div>
<div class="form-group">
<label for="exampleactive1">Active (0=Not Active, 1=Active)</label>
<input type="text" class="form-control" id="active" placeholder="Enter 0 or 1">
</div>
</div>
<!-- /.box-body -->
<div class="box-footer">
<input type="button" class="btn btn-primary" onClick="UpdateMailbox()" value="Update"></input>
</div>
</form>
</div>
<!-- /.box -->
</div>
</div>
</div>';
include('../master.php');
?>
<script>
$(document).ready(function(){
$.ajax({
type: "GET",
url: "../api/mailbox/read_single.php?mailbox_id=<?php echo $_GET['mailbox_id']; ?>",
dataType: 'json',
success: function(data) {
$('#username').val(data['username']);
$('#password').val(data['password']);
$('#name').val(data['name']);
$('#maildir').val(data['maildir']);
$('#quota').val(data['quota']);
$('#local_part').val(data['local_part']);
$('#domain').val(data['domain']);
$('#created').val(data['created']);
$('#modified').val(data['modified']);
$('#active').val(data['active']);
$('#mailbox_id').val(data['mailbox_id']);
},
error: function (result) {
console.log(result);
},
});
});
function UpdateMailbox(){
$.ajax(
{
type: "POST",
url: '../api/mailbox/update.php',
dataType: 'json',
data: {
mailbox_id: <?php echo $_GET['mailbox_id']; ?>,
username: $("#username").val(),
password: $("#password").val(),
name: $("#name").val(),
maildir: $("#maildir").val(),
quota: $("#quota").val(),
domain: $("#domain").val(),
modified: $("#modified").val(),
active: $("#active").val()
},
error: function (result) {
alert(result.responseText);
},
success: function (result) {
if (result['status'] == true) {
alert("Successfully Updated Mailbox!");
window.location.href = '/MailEasy/mailbox/listAll.php';
}
else {
alert(result['message']);
}
}
});
}
</script>
1) Why is not updating when using web UI?
2) When using postman, it shows successful, why are requests not reaching the database?
Postman --> Successful response but no changes in db.
Php webpage --> Mailbox already exists.
Thank you

unable to insert record through jquery ajax

Right now I am facing a problem : I am trying to insert records in the database with the help of jQuery & Ajax. Unfortunately, I tried to alert inserted values but It doesn't show. I also checked through serialize function and I am unable to do that.
Here is my code of ajax
<script type="text/javascript">
$(document).ready(function(){
$("#add_new").click(function(){
$("#add").slideToggle();
});
$("#submit").click(function(){
var stud_no=$("#roll").val();
if(stud_no==''){
$("#msg").html("Input Roll Number");
} else {
var datastr = $("#sampleform").serialize();
alert(datastr);
$.ajax({
type:'POST',
url:'add_it.php',
data:datastr,
success:function(response){
$("#my_form")[0].reset();
$("#msg").html("Student Successfully Added");
},
error: function (xhr, ajaxOptions, thrownError) {
}
});
}
});
});
</script>
Here is body code :
<body>
<a id="add_new">+add new item</a><br /><br />
<div id="msg"></div><br />
<div id="add">
<form id="sampleform">
<fieldset>
<div class="form-group row">
<label for="roll" class="col-sm-2 col-form-label">Roll Number</label>
<div class="col-sm-6">
<input type="text" name="roll" class="form-control" id="roll">
</div>
</div>
<div class="form-group row">
<label for="name" class="col-sm-2 col-form-label">Name</label>
<div class="col-sm-6">
<input type="text" name="name" class="form-control" id="name">
</div>
</div>
<div class="form-group row">
<label for="clas" class="col-sm-2 col-form-label">Class</label>
<div class="col-sm-6">
<input type="text" name="standard" class="form-control" id="standard">
</div>
</div>
<div class="form-group row">
<label for="mail" class="col-sm-2 col-form-label">Email</label>
<div class="col-sm-6">
<input type="email" name="mail" class="form-control" id="mail">
</div>
</div>
<button type="submit" id="submit" class="btn btn-primary">Submit</button>
<button type="reset" class="btn btn-default">Reset</button>
</fieldset>
</fieldset>
</form>
</div>
Here is my add_it.php
<?php
include('connectdb.php');
$stud_no = trim($_POST['stud_no']);
$name = trim($_POST['name']);
$standard = trim($_POST['standard']);
$mail = trim($_POST['mail']);
$query = "insert into student (stud_no,name,standard,email) values ('$stud_no','$name','$standard','$mail')";
mysqli_query($con,$query) or die (mysqli_error());
?>
Your HTML form fields doesnt have any of these variables sent. You need to add name="email" etc to your form fields.
So for example the email field has to look like this:
<input type="email" name="email" class="form-control" id="mail">
id, class etc is not sent in POST - and therefor can not be recieved in the other end.
Jquery's serialize() function also only handles "name" fields.
https://api.jquery.com/serialize/
Snippet :
For a form element's value to be included in the serialized string, the element must have a name attribute

ajax doesn't work with php

I've been trying to use ajax to insert data into my database but it didn't work. So I wrote a code to try a basic call for a php file and it didn't work either:
here is my html code :
<form >
<h4 class="header-title m-t-0 m-b-30">Cordonnées de facturation</h4>
<div class="form-group">
<label class="col-md-4 control-label">code facture</label>
<div class="col-md-6">
<input type="text" id="code_facture" class="code_facture form-control" placeholder="Ex : 008A00098">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Numéro du dossier</label>
<div class="col-md-6">
<input type="text" id="code_dossier" class="code_dossier form-control" placeholder="Ex : 008A00098">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">TPS</label>
<div class="col-md-6">
<input type="text" id="tps" class="tps form-control" placeholder="Ex : 0">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">TVQ</label>
<div class="col-md-6">
<input type="text" id="tvq" class="tvq form-control" placeholder="Ex : 0">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Référence</label>
<div class="col-md-6">
<input type="text" id="reference" class="reference form-control" placeholder="Ex : VAR R4055555">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">PNR</label>
<div class="col-md-6">
<input type="text" id="pnr" class="pnr form-control" placeholder="Ex : M15478LD265">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Date de facturation</label>
<div class="col-md-6">
<input type="text" placeholder="12/12/2012" data-mask="99/99/9999" id="date_facturation" class="date_facturation form-control">
<span class="font-13 text-muted">jj/mm/aaaa</span>
</div>
</div>
<div class="form-group">
<button type="submit" class="btn" id="addfacturebutton"> ajouter</button>
</div>
and here is my ajax script
<script>
$('#addfacturebutton').click(function(e){
e.preventDefault();
$.ajax({
type: 'POST',
url: 'insertFacture.php',
data:{
code_facture:$('input[id=code_facture').val(),
code_dossier:$('input[id=code_dossier').val(),
tps:$('input[id=tps').val(),
tvq:$('input[id=tvq').val(),
reference:$('input[id=reference').val(),
pnr:$('input[id=pnr').val(),
date_facturation:$('input[id=date_facturation').val(),
},
success:function(data){
},
});
});
</script>
so in my php file I tried to write die('test'); but inserting into database didn't work either.
it doesn't call the functions
here is my php file:
<?php
include('functions.php');
$data = $_POST['code_dossier'];
die('works');
?>
Have you tried to dump $_POST of your insertFacture.php file? It seems like you do have wrong php filename or something wrong with the functions.php
Your code does not confirm if the js code works or not.
Try this:
Change this line:
success:function(data){
}
to:
success:function(data){
alert(data)
}
And change every occurrence of:
').val()
to
]').val()
If there is an alert, then the js is working. And I cannot see anything related to database in your php code.
To reduce the lines of code in ajax, you can alternatively add an id attribute on the form tag and then either serialize() or use FormData()
<form id='myFormTag'>
Then in ajax, simply call FormData() on submit()
$('#myFormTag').submit(function(e){
e.preventDefault();
$.ajax({
data: new FormData(this),
//other AJax Stuff
success:function(data){
alert(data)
}
});
});

Bind input type file using rivets js

I am using Rivets to bind my form data. Is there any way to bind my input type file with the help rivet binders.
Like in this example https://jsfiddle.net/steinbring/v29vnLuh/ You can see that we bind text area . But how will we bind over input file .
Let me explain more
here is my form
<form class="product-inputs full-width-inputs" method="post" action="/create/save-manual-products-shopify">
<section id="rivettest">
<ul class="no-bullet">
<li class="product-input-header">
<div class="row no-padding">
<div class="small-2 columns">
<p>Product Name</p>
</div>
<div class="small-2 columns">
<p>Product Detail</p>
</div>
<div class="small-2 columns">
<p>Product Type</p>
</div>
<div class="small-2 columns">
<p>Price</p>
</div>
<div class="small-2 columns floatleft">
<p>Sku</p>
</div>
<div class="small-2 columns floatleft">
<p>Image</p>
</div>
</div>
</li>
<li class="product-input" rv-each-product="products">
<div class="row no-padding">
<div class="small-2 columns" style="position: relative">
<input class="product-name-input" type="text" rv-value="product.name" placeholder="New Product"/>
<span class="icon-error remove-btn" rv-on-click="controller.removeItem"></span>
</div>
<div class="small-2 columns">
<input type="text" rv-value="product.product_detail"/>
</div>
<div class="small-2 columns">
<input type="text" rv-value="product.product_type"/>
</div>
<div class="small-2 columns">
<input type="text" rv-value="product.price">
</div>
<div class="small-2 columns">
<input type="text" rv-value="product.sku">
</div>
<div class="small-2 columns">
<input type="file" rv-value="product.image">
<!-- <input type="file"> -->
<!-- <span class="icon-upload"></span> Upload Image -->
</div>
</div>
</li>
<li class="additem">
<span class="icon-plus"></span>Add Product Manually
</li>
</ul>
</section>
<input type="submit" value="Submit for KF Approval" class="button radius add-product-shopify" >
</form>
And here is my script
var products = [];
var controller = {
addItem: function(e, model) {
model.products.push({name: "New Product", product_detail: "", product_type: "", price: null, sku: null, image: ""});
e.preventDefault();
return false;
},
removeItem: function(e, model) {
var index = model.index;
if (index > -1) {
products.splice(index, 1);
}
},
};
rivets.bind($('#rivettest'), {products: products, controller: controller});
But when i submit my form i got this response
image: ""
name: "a"
price: "12"
product_detail: "b"
product_type: "c"
sku: "12"
Here you see that image param is empty ... please help me .Thanks
Here's a working example written in coffescript
controller = (el, data) ->
that = this
#email_valid = false
#update = ->
if #type == "file"
data[#id] = #files[0]
else
data[#id] = #value
#submit = ->
_data = new FormData()
Object.keys(data).forEach( (key) ->
_data.append(key, data[key])
)
req = new XMLHttpRequest()
req.open('POST', 'addUser', true)
req.onreadystatechange = (aEvt) ->
if req.readyState == 4
if req.status == 200
return req.responseText
else
return "Erreur pendant le chargement de la page.\n"
req.send(_data)
#email_validate = ->
re = /\S+#\S+\.\S+/
return re.test data.email
return this
rivets.components['user'] = {
# Return the template for the component.
template: ->
return tpl
# Takes the original element and the data that was passed into the
# component (either from rivets.init or the attributes on the component
# element in the template).
initialize: (el, data) ->
return new controller(el, data)
}
the form
<form enctype="multipart/form-data" class="form-horizontal" id="userForm">
<fieldset>
<!-- Form Name -->
<legend>Form Name</legend>
<!-- File Button -->
<div class="form-group">
<label class="col-md-4 control-label" for="picture">Photo</label>
<div class="col-md-4">
<input rv-value="picture" rv-on-change="update" id="picture" name="picture" class="input-file" type="file">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="textinput">Name</label>
<div class="col-md-4">
<input rv-value="name" id="name" rv-on-input="update" name="name" type="text" placeholder="Name" class="form-control input-md">
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="password">Password</label>
<div class="col-md-4">
<input rv-value="password" id="password" rv-on-input="update" name="password" type="text" placeholder="Password" class="form-control input-md">
</div>
</div>
<!-- Password input-->
<div class="form-group">
<label class="col-md-4 control-label" for="password-validate">Password Validate</label>
<div class="col-md-4">
<input rv-value="password-validate" rv-on-input="update" id="password-validate" name="password-validate" type="password" placeholder="Password" class="form-control input-md">
</div>
</div>
<!-- Button -->
<div class="form-group">
<label class="col-md-4 control-label" for="save">Save</label>
<div class="col-md-4">
<button type="button" rv-on-click="submit" id="save" name="save" class="btn btn-primary">Save</button>
</div>
</div>
</fieldset>
</form>
and the server side
multipart = require('connect-multiparty');
multipartMiddleware = multipart();
app.post '/addUser', multipartMiddleware, (req, resp) ->
console.log(req.body, req.files)
You need to set your form to allow file upload using the enctype attribute.
<form enctype="multipart/form-data">
You can try to bind an onchange event to the file input:
<input type="file" rv-on-change="update" rv-value="product.image">
and create an update method in your controller that update the product.image value with the value of form.
this.update = function(){
model[this.id] = this.value
}

Uploading files to Amazon S3 with PHP ends up with a 28 byte file

I am working on a project where users can upload files to the site that is stored in an Amazon S3 bucket.
This doesn't really work though.. The server sees the file and everything seems good, apart from the file only being 28 bytes big when it ends up on amazon..
This is my code so far:
controller
public function uploadFile()
{
$data['username'] = $this->input->cookie('username', TRUE);
$data['pagetitle'] = "Upload file";
$data['userid'] = $this->userid;
$this->load->template('uploadFile', $data);
}
public function takeUpload()
{
$config['upload_path'] = './images/screenshots/';
$config['allowed_types'] = 'gif|jpg|png';
$config['encrypt_name'] = TRUE;
$this->load->library('upload', $config);
$projectFileLoc = $_FILES['projectFile']['tmp_name'];
$projectFileName = $_FILES['projectFile']['name'];
if (!($this->upload->do_upload("previewImage")) && !($this->s3->putObject($projectFileLoc, '3dnation', $projectFileName, $this->s3->ACL_PUBLIC_READ)))
{
echo "Something went wrong...";
}
else
{
$imgData = $this->upload->data();
$previewImage = $imgData['file_name'];
//TODO: Add image to DB
}
}
The view file (uploadFile.php)
<div class="row">
<div class="col-xs-12 col-sm-12">
<div class="jumbotron">
<h1>Upload files</h1>
</div>
</div><!--/span-->
</div><!--/row-->
<div class="row">
<div class "col-xs-12 col-sm-12">
<form action="/home/takeUpload" method="POST" role="form" class="form-horizontal" enctype="multipart/form-data">
<div class="form-group">
<label for="title" class="col-sm-2 control-label">Title</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="title" placeholder="Title" name="title" required>
</div>
</div>
<div class="form-group">
<label for="description" class="col-sm-2 control-label">Description</label>
<div class="col-sm-10">
<input type="textfield" class="form-control" id="description" placeholder="Enter a description here" name="description" required>
</div>
</div>
<div class="form-group">
<label for="projectFile" class="col-sm-2 control-label">Project/Scene files (accepted formats: zip, rar, 3ds)</label>
<div class="col-sm-10">
<input type="file" class="form-control" id="projectFile" name="projectFile" required>
</div>
</div>
<div class="form-group">
<label for="previewImage" class="col-sm-2 control-label">Preview image</label>
<div class="col-sm-10">
<input type="file" class="form-control" id="previewImage" name="previewImage" required>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">Upload</button>
</div>
</div>
</form>
</div>
</div>
I am building it with the latest Codeigniter with this S3 library
What is wrong?
You must call to putObject with an array, if you want use a file you must call too "putObjectFile" function:
Check the definition in the class:
public static function putObjectFile($file, $bucket, $uri, $acl = self::ACL_PRIVATE, $metaHeaders = array(), $contentType = null)
{
return self::putObject(self::inputFile($file), $bucket, $uri, $acl, $metaHeaders, $contentType);
}
A example from the original library:
// Simple PUT:
if (S3::putObject(S3::inputFile($file), $bucket, $uri, S3::ACL_PRIVATE)) {
echo "File uploaded.";
} else {
echo "Failed to upload file.";
}
As you can see in the doc

Categories