[eluser]Unknown[/eluser]
Hello, i'm trying to make an AJAX uploader and i did not work for now, but yesterday it works, haha.
Code:
$('form.#upload-photo').submit(function() {
$.ajaxFileUpload ({
url: 'players/uploadPhoto',
secureuri: false,
fileElementId: 'playerphoto',
dataType: 'json',
data: {
'csrf_token_name': $('input[name=csrf_token_name]').val(),
'playerid': $('input[name=playerid]').val()
},
success: function (data, status) {
$('#dialog1 .message').removeClass('succes, warning, error')
$('#dialog1 .message').fadeOut(250).addClass(data.type).fadeIn(250).html(data.message);
}
});
return false;
});
This is my view:
Code:
<?= form_open_multipart('', array('method' => 'post', 'id' => 'upload-photo')); ?>
<?= form_input(array(
'id' => 'playerid',
'name' => 'playerid',
'value' => @$row->playerID,
'type' => 'hidden'));
?>
<?= form_input(array(
'id' => 'playerphoto',
'name' => 'playerphoto',
'type' => 'file',
'class' => 'selectfile'));
?><br />
<?= form_submit('submit', 'Uploaden', 'id="submit"'); ?>
<?= form_close(); ?>
And this is my controller:
Code:
function uploadPhoto() {
$this->form_validation->set_rules('playerid', 'playerID', 'required|trim|numeric');
if ($this->form_validation->run() == true)
{
$valid = false;
$message = 'Het uploaden is mislukt';
$config['upload_path'] = 'media/uploads/images/players/';
$config['allowed_types'] = 'jpg|jpeg|png|gif';
$config['remove_spaces'] = true;
$config['overwrite'] = true;
$config['file_name'] = sha1($this->input->post('playerid')) . '.jpg';
$this->upload->initialize($config);
if ($this->upload->do_upload('playerphoto') AND chmod('media/uploads/images/players/' . sha1($this->input->post('playerid')) . '.jpg', 0777))
{
$config['image_library'] = 'gd2';
$config['source_image'] = 'media/uploads/images/players/' . sha1($this->input->post('playerid')) . '.jpg';
$config['width'] = 150;
$config['height'] = 150;
$config['quality'] = '100%';
if ($this->image_lib->initialize($config) AND $this->image_lib->resize())
$valid = true;
$message = 'Het uploaden is gelukt';
}
General::jsonArray($valid, $message);
}
redirect($this->router->class);
}
I hope that anybody can help me. CodeIgniter says i don't have selected a file to upload.