Welcome Guest, Not a member yet? Register   Sign In
Retrieve uploaded file name
#1

[eluser]Jackattack[/eluser]
Code:
$this->upload->data()
This is a helper function that returns an array containing all of the data related to the file
you uploaded. Here is the array prototype:

Array
(
    [file_name]    => mypic.jpg
    [file_type]    => image/jpeg
    [file_path]    => /path/to/your/upload/
    [full_path]    => /path/to/your/upload/jpg.jpg
    [raw_name]     => mypic
    [orig_name]    => mypic.jpg
    [file_ext]     => .jpg
    [file_size]    => 22.2
    [is_image]     => 1
    [image_width]  => 800
    [image_height] => 600
    [image_type]   => jpeg
    [image_size_str] => width="800" height="200"
)

Is there a way to pull the file_name out of that array in the controller so I can send it to my model?

Basically I'd like to write the uploaded image name to the database but I need the name to send it to my model. This appears to be what I want, but I can't find out how to pull the information out of the array or if I need to initialize it first before I can do so.

Thanks for the help!!
#2

[eluser]Armchair Samurai[/eluser]
Assign $this->upload->data() to a variable, then pass that to the model.
Code:
$file = $this->upload->data();

$this->Your_model->your_function($file['file_name']);
#3

[eluser]Jackattack[/eluser]
Thank you, it worked perfectly, but sadly it turned out to not be exactly right. What I get is the original filename, but my problem or what I really need is the file name that code igniter gives to the file once it realizes that the filename is already there or used.

It works perfectly if it doesn't match a filename already in the folder, but when it does it saves the file as cat1.jpg but what I get back is the original filename of cat.jpg. Anyway around that?

Does that make sense?

Thanks for the help!
#4

[eluser]Jackattack[/eluser]
Thanks for the help, but turns out that the raw_file field in the array is what I was looking for. It doesn't seem to specify all the differences between it and the file_name field in the user guide and might be helpful if it did. Anyway no biggy and it's working perfectly now! Thanks!




Theme © iAndrew 2016 - Forum software by © MyBB