Welcome Guest, Not a member yet? Register   Sign In
Solved: non-object error
#1

(This post was last modified: 04-28-2018, 08:41 AM by davy_yg.)

Hello,

I am trying to view the file image after uploading and I am getting non-object error.  How to call the file name?

upload_success.php

Code:
[code]
<html>
<head>
<title>Upload Form</title>
</head>
<body>

<h3>Your file was successfully uploaded!</h3>

<ul>
<?php foreach ($upload_data as $item => $value):?>
<li><?php echo $item;?>: <?php echo $value;?></li>
<?php endforeach; ?>
</ul>

        <img src="uploads/".$upload_data->file_name>

<p><?php echo anchor('upload', 'Upload Another File!'); ?></p>

</body>
</html>[/code]
" If I looks more intelligence please increase my reputation."
Reply
#2

Because it is an Associated array and your trying to access it as an object.

Do you even know the difference between an associated array or an object etc;?
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

associated array something like:

https://www.w3schools.com/php/php_arrays.asp ?

How to fix the code?
" If I looks more intelligence please increase my reputation."
Reply
#4

I already able to capture the file name but unable to print it out correctly.

controllers/upload_image.php

$data = array('upload_data' => $this->upload->data(),
'file_name' => $this->upload->data('file_name')
);

$this->photo_model->insert_pic();

$this->load->view('upload_success', $data);

views/upload_success.php

<img scr="uploads/"<?php echo $file_name; ?>>

If I checked through inspect element I get this html code:

<img src="uploads/"davy210.png="">

which is in correct.
" If I looks more intelligence please increase my reputation."
Reply
#5

I finally find the answer to this one! Thanks.

<img src="<?php echo base_url('/uploads/'.$file_name); ?>">
" If I looks more intelligence please increase my reputation."
Reply




Theme © iAndrew 2016 - Forum software by © MyBB