Welcome Guest, Not a member yet? Register   Sign In
File upload fail on iphone safari ?
#1

I've using CI 2.2 to made simple form with attachment/file upload. Everything working fine except on iphone safari browser. When people attach an image from iphone safari, the filename was keep renamed into image.jpg. This causing problem where attachment from different person keep showing same image.

I used filename encryption provided by CI but still no luck. Below is file upload setting:

Code:
function attachment()
{
  $config['upload_path'] = 'uploads/';
  $config['allowed_types'] = 'gif|jpg|png|zip|rar|pdf';
  $config['max_size'] = '3000';
  $config['max_width'] = '2000';
  $config['max_height'] = '2000';
  $config['encrypt_name'] = true;
  $this->upload->initialize($config);
}

Thank you very much.
Reply
#2

if your problem is related to same names just generate custom name hashes as :
Code:
md5 ( microtime(TRUE) . $userid )
This will generate hash related to the current microtime and client id..
Best VPS Hosting : Digital Ocean
Reply
#3

(This post was last modified: 11-11-2014, 04:27 AM by Rufnex.)

I think you have to rename the uploaded filename each time, otherwise you allways overwrite it with the new on. you can set this bei the file_name hash. for e.g.

Code:
$this->load->helper('inflector');
$file_name = underscore($_FILES['file_var_name']['name']);
$config['file_name'] = $file_name;

or this should also work with a custom name logic

$config['file_name'] = 'your_file_name';

Look at http://www.codeigniter.com/user_guide/li...ading.html

Reply
#4

Or you can just use the "encrypt_name " param from the upload lib and set the "overwrite" to false. That way all the uploads will have a different random name and they will not be overwritten.
Website: marcomonteiro.net  | Blog: blog.marcomonteiro.net | Twitter: @marcogmonteiro | TILThings: tilthings.com
Reply
#5

(11-11-2014, 04:30 AM)marcogmonteiro Wrote: Or you can just use the "encrypt_name " param from the upload lib and set the "overwrite" to false. That way all the uploads will have a different random name and they will not be overwritten.

If you use anything from the user, make sure that they have not attempted to put some kind of code or execution path etc. in the file name.

If you accept user input, you must sanitize it before use.

So using a name generated on the server and only transferring the contents to your own location with your file name, makes it very hard from them to run or change code on the server.
Reply
#6

Hi guys,

Sorry for late reply. I already try the suggestion above but keep the same result. And its not a overwrite problem. The problem is even the encrypt name option is set to true the image recorded on the database still as image.jpg no matter what filename user has attached from their iphone.

I think when encrypt name is true, 2 people attach different file, lets says image.jpg & image2.jpg will generating 2 different hashed name. In fact its not when using iphone safari.

Thats what the issue i faced, server or code fail ?

Thanks.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB