• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Manipulte uploaded file before saving

#1
[eluser]Bursh[/eluser]
Hey

I'm trying to manipulate an uploaded files name before saving it in the folder (so that I have a regular naming convention within the folders) but I can't seem to find any function that would allow that in CI. Can anybody help me out on this one?

Regards,
Bursh.

#2
[eluser]fatnic[/eluser]
You could upload the file into a temp directory. Then do your 'manipulations', copy to permanent folder, then delete the temp file.

#3
[eluser]Bursh[/eluser]
[quote author="fatnic" date="1219696045"]You could upload the file into a temp directory. Then do your 'manipulations', copy to permanent folder, then delete the temp file.[/quote]

I'd rather not do that, unless I have to, because that's a really long way around it.

#4
[eluser]fatnic[/eluser]
Well after a quick re-read of the user guide, I can't see any way of changing the filename before you upload.

The only way I can think of to do it is not use the CodeIgniter upload library and use native PHP instead.

#5
[eluser]Bursh[/eluser]
[quote author="fatnic" date="1219700026"]Well after a quick re-read of the user guide, I can't see any way of changing the filename before you upload.

The only way I can think of to do it is not use the CodeIgniter upload library and use native PHP instead.[/quote]

I thought of that too. I guess I'll try it that way unless anybody else can come up with a way.

#6
[eluser]fesweb[/eluser]
It depends on what you mean by "before." You can rename the file without creating a temporary file to be deleted.
Code:
$base_name = 'upload'.$id;

$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'pdf|doc';
$config['max_size'] = '2048';
$config['encrypt_name'] = TRUE;

$this->upload->initialize($config);
$this->fileinfo = $this->upload->data();

$base_name_full_path = $this->fileinfo['file_path'].$base_name.$this->fileinfo['file_ext'];

$rename_it = rename($this->fileinfo['full_path'], $base_name_full_path);
Does that do anything for you?

#7
[eluser]Bursh[/eluser]
[quote author="fesweb" date="1219710167"]It depends on what you mean by "before." You can rename the file without creating a temporary file to be deleted.
Code:
$base_name = 'upload'.$id;

$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'pdf|doc';
$config['max_size'] = '2048';
$config['encrypt_name'] = TRUE;

$this->upload->initialize($config);
$this->fileinfo = $this->upload->data();

$base_name_full_path = $this->fileinfo['file_path'].$base_name.$this->fileinfo['file_ext'];

$rename_it = rename($this->fileinfo['full_path'], $base_name_full_path);
Does that do anything for you?[/quote]

Works an absolute charm. Thank you very much.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.