Codeigniter do_upload doesn't response in production server - El Forum - 09-10-2012
[eluser]mF4d[/eluser]
Hi guys,
I think I should ask the problem here, I've been trying to figure this out.
I made a page that will upload certain file types. It works fine in my local development but not in production.
It won't pass the do_upload() function. Nothing is displayed beyond that.
My folder structures:
Code: public_html/gtapp/
public_html/gtapp/csystem/ <- is system folder
public_html/gtapp/v1/ <- is application folder
public_html/gtapp/media/
public_html/gtapp/uploads/
public_html/gtapp/license.txt
In config.php:
Code: $config['base_url'] = 'http://www.mydomain.com/gtapp/
In index.php:
Code: $application_folder = 'v1';
The uploads folder permission is 777.
I tried changing the upload_path to non existing folder, it show 'The upload path does not appear to be valid'. Means the do_upload() does work right?
Below is codeigniter codes:
Code: $path = 'uploads';
echo 'path: '. $path .' <br>';
//-- config for uplaod --
$configUpdload['upload_path'] = $path ;
$configUpdload['allowed_types'] = 'gif|jpg|png|xls|xlsx|pdf';
$configUpdload['max_size'] = '4000'; //size in kilobytes
$configUpdload['encrypt_name'] = TRUE;
//-- load upload library --
$this->load->library('upload');
$this->upload->initialize($configUpdload);
if ($_FILES['fileref']['name']!="")
{
ini_set('display_errors', true);
error_reporting(E_ALL);
echo 'uploadAttachment<br>';
print_r($_FILES).'<br>'; //edit, added
$uploaded = $this->upload->do_upload("fileref");
echo 'uploaded: '. $uploaded . '<br>';
if ($uploaded == true)
{
echo 'uploaded data<br>';
$inputUp = $this->upload->data();
echo 'data: '. print_r($inputUp,true) . '<br>';
$uploadInput['orig_name'] = $inputUp['orig_name'];
$uploadInput['enc_name'] = $inputUp['file_name'];
$uploadInput['extension'] = $inputUp['file_ext'];
echo 'uploaded true<br>';
}else{
die($this->upload->display_errors());
}
}
I made a simple native PHP codes and it works. Below is the code:
Code: $path = './uploads/';
$name = 'fileref';
$upload_path = 'uploads/';
$allowed_types = array("jpg", "jpeg", "gif", "png", "xls", "xlsx", "pdf");
$extension = end(explode(".", $_FILES[$name]["name"]));
$max_size = '4000';
if ($_FILES['fileref']['name']!="")
{
if ((($_FILES[$name]["type"] == "image/gif")
|| ($_FILES[$name]["type"] == "image/jpeg")
|| ($_FILES[$name]["type"] == "image/pjpeg")
|| ($_FILES[$name]["type"] == "image/png")
|| ($_FILES[$name]["type"] == "image/x-png")
|| ($_FILES[$name]["type"] == "application/excel")
|| ($_FILES[$name]["type"] == "application/vnd.ms-excel")
|| ($_FILES[$name]["type"] == "application/msexcel")
|| ($_FILES[$name]["type"] == "application/pdf")
|| ($_FILES[$name]["type"] == "application/x-download"))
&& (round($_FILES[$name]["size"]/1024,2) < $max_size )
&& in_array($extension, $allowed_types))
{
if ($_FILES[$name]["error"] > 0)
{
echo $_FILES[$name]["error"]);
}
else
{
$uploadInput['orig_name'] = $_FILES[$name]["name"];
$uploadInput['enc_name'] = sha1($_FILES[$name]["name"]);
$uploadInput['extension'] = $_FILES[$name]["type"];
$moved = move_uploaded_file($_FILES[$name]["tmp_name"], $upload_path . $uploadInput['enc_name'] . '.' . $extension);
if($moved)
echo 'success';
else
echo 'fail';
}
}
}
do_upload() does simplify things a lot, I hope could use it before turning over to the native codes.
Maybe someone have some ideas on what happen? That would be great.
*cross post http://stackoverflow.com/questions/12337132/codeigniter-do-upload-doesnt-response-in-production-server
I apologize for cross posting.
Codeigniter do_upload doesn't response in production server - El Forum - 09-10-2012
[eluser]siptik[/eluser]
Do you have the message "uploadAttachment" after posting form?
sorry, i bad english
Codeigniter do_upload doesn't response in production server - El Forum - 09-10-2012
[eluser]mF4d[/eluser]
Yes, 'uploadAttachment' is showing.
I add print_r($_FILE); just before the do_upload, will edit above post.
Below is what showing with the above codes.:
Code: uploadAttachment
path: uploads
Array ( [fileref] => Array ( [name] => test.png [type] => image/png [tmp_name] => /tmp/php0LGuoD [error] => 0 [size] => 90019 ) )
When run in the local:
Code: uploadAttachment
path: uploads
Array ( [fileref] => Array ( [name] => test.png [type] => image/jpeg [tmp_name] => /Applications/MAMP/tmp/php/phpiJ6NcX [error] => 0 [size] => 90019 ) )
uploaded: 1
uploaded data
data: Array ( [file_name] => 91252803d7f5d3a48cf2d5b6fced4a7e.png [file_type] => image/png [file_path] => /Applications/MAMP/htdocs/gtapp/uploads/ [full_path] => /Applications/MAMP/htdocs/gtapp/uploads/91252803d7f5d3a48cf2d5b6fced4a7e.png [raw_name] => 91252803d7f5d3a48cf2d5b6fced4a7e [orig_name] => test.png [client_name] => test.png [file_ext] => .png [file_size] => 87.91 [is_image] => 1 [image_width] => 724 [image_height] => 114 [image_type] => png [image_size_str] => width="724" height="114" )
uploaded true
Codeigniter do_upload doesn't response in production server - El Forum - 09-11-2012
[eluser]siptik[/eluser]
maybe you forgot to allow access to the folder in .htaccess?
Codeigniter do_upload doesn't response in production server - El Forum - 09-11-2012
[eluser]mF4d[/eluser]
[quote author="siptik" date="1347349567"]maybe you forgot to allow access to the folder in .htaccess?[/quote]
Thanks, but I didn't set any .htaccess. Is that the case? What should I set in them?
I think the folder can be accessed because the native php code I wrote to upload the file is working fine in production.
|