سلام من می خوام توسط jquery و php فایل upload کنم
کد جاوا اسکریپتم اینه
[JSS]
$("#newsImg").change(function () {
var img = $("#newsImg").val();
var postURL = $("#url").val();
$.ajax({
url: postURL+'index.php/news/do_upload',
type:'POST',
dataType: 'json',
enctype: 'multipart/form-data',
data: {'file' : img},
success: function(output_string){
$("#newsContent").html(output_string);
}
});
});
[/JSS]
و کد php هم اینه
[PHPS] function do_upload()
{
$config['upload_path'] = './files/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '1000';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
$this->upload->initialize($config);
if ( ! $this->upload->do_upload())
{
$data = array('error' => $this->upload->display_errors());
}
else
{
$data = array('upload_data' => $this->upload->data());
}
echo json_encode($data);
}
[/PHPS]
من با code igniter کار می کنم ولی فایل سمت server ارسال نمی شه
کسی می تونه کمک کنه؟
کد جاوا اسکریپتم اینه
[JSS]
$("#newsImg").change(function () {
var img = $("#newsImg").val();
var postURL = $("#url").val();
$.ajax({
url: postURL+'index.php/news/do_upload',
type:'POST',
dataType: 'json',
enctype: 'multipart/form-data',
data: {'file' : img},
success: function(output_string){
$("#newsContent").html(output_string);
}
});
});
[/JSS]
و کد php هم اینه
[PHPS] function do_upload()
{
$config['upload_path'] = './files/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '1000';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
$this->upload->initialize($config);
if ( ! $this->upload->do_upload())
{
$data = array('error' => $this->upload->display_errors());
}
else
{
$data = array('upload_data' => $this->upload->data());
}
echo json_encode($data);
}
[/PHPS]
من با code igniter کار می کنم ولی فایل سمت server ارسال نمی شه
کسی می تونه کمک کنه؟