Upload with new file name. |
[eluser]Arun Joshi[/eluser]
I have to upload an image. That image may be jpg,png or gif. When uploading I want to rename the file. I tried $config['file_name'] = 'newname.gif';. It works. But I want to rename the file name part only. Not the extension. eg: If any upload a file 'anyname.jpg', it should upload as 'myname.jpg'. If any upload a file 'anyname.gif', it should upload as 'myname.gif'.
[eluser]Clooner[/eluser]
[quote author="Arun Joshi" date="1281626857"]I have to upload an image. That image may be jpg,png or gif. When uploading I want to rename the file. I tried $config['file_name'] = 'newname.gif';. It works. But I want to rename the file name part only. Not the extension. eg: If any upload a file 'anyname.jpg', it should upload as 'myname.jpg'. If any upload a file 'anyname.gif', it should upload as 'myname.gif'.[/quote] AFAIK when you set the filename without an extension CI will atomatically set the right extension for you.
[eluser]mi6crazyheart[/eluser]
When u r using that, "file_name" just do in this way... Code: $newName = "myname";
[eluser]verynewtothis[/eluser]
First, I hope you are using CI 1.7.2. If you are not then I would suggest you to use the PHP's built in rename function. This thread might help as well: Click here [Edit] Excellent suggestions by mi6crazyheart and clooner
[eluser]Arun Joshi[/eluser]
Am using 1.7.2. When I gave a file name without an extension, it shows the following error. The filetype you are attempting to upload is not allowed. I have set this $config['allowed_types'] = 'gif|jpg|png'; Is this the reason?
[eluser]Narkboy[/eluser]
I have this same issue. The user_guide _clearly_ states that you must not include a file ext in the upload preferences [file_name]: "Note:The filename should not include a file extension." However, if you do not, then when you run the upload, you always get a 'filetype not allowed' error. Adding an ext to the [file_name] solves this issue. Anyone else getting that? Not sure if it's an issue with the new version of file_upload, a mistake in the user_guide or a problem with some specific instances. Weird - but Arun, you are not alone!! /B
[eluser]Unknown[/eluser]
Hi, I have this same issue with CI 1.7.2 It works if define the extension ([file_name'] => 'myfilename.jpg'), but [file_name'] => 'myfilename' doesn't work.
[eluser]1mr3yn[/eluser]
try this.,. Code: $config = array ( |
Welcome Guest, Not a member yet? Register Sign In |