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?