1

Im using codeigniters file upload library .... everything works fine except i want to output the uploaded file details.

I have the following code

$uploaddata = $this->upload->data('userfile');
foreach($uploaddata as $details){
    echo $details['file_name'];
}

The above code keeps erroring with the following

Message: Undefined index: file_name

Could someone let me know where im going wrong,

Cheers

1
  • Could you provide more code. The form validation, the full callback, etc. Commented Dec 8, 2010 at 12:13

1 Answer 1

1

I don't know the problem, but I think it will help you if you first know "what is the content of $uploaddata" by writing: var_dump($uploaddata) just before foreach loop...

Sign up to request clarification or add additional context in comments.

7 Comments

The results from the var_dump are very confusing .... it echoed the following ... array(13) { ["file_name"]=> array(1) { [0]=> string(21) "Air-Max-1-Premium.jpg" } ["file_size"]=> array(1) { [0]=> float(63.78) } ["file_type"]=> array(1) { [0]=> string(10) "image/jpeg" }
I sent one comment, but it was wrong and I deleted it... I looked at my codes: $upload_data = $this->upload->data(); $file_name = $upload_data['file_name']; $file_path = $upload_data['full_path']; I think you can not use foreach in that way, because in every cycle it will return it's content...
When i echo out $file_name, it just returns 'Array'
try this one: foreach($uploaddata as $detailkey => $detail){ if (is_array($detail)){ echo $detailkey ." = ". $detail[0] ."<br>"; } elseif(!is_null($detail)) { echo $detailkey ." = ". $detail ."<br>"; } }
That works perfect if there is only one file ... what happens if there are multiple file fields with names like userfile[] ... it only echos out the information for the first file uploaded ... weird
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.