Image display codeigniter fails - image

I can upload image to the directory but can not disply it on the page.
Tried using static html code and codeigniter img() function, both are not working.
Here is my code:
<image src="./applications/views/uploads/image.jpeg" />
and
$this->output->set_header("Content-Type: image/jpeg");
$data['image'] = $this->load->file('../uploads/taurus.jpeg');
the first code shows me broken image the second one shows Unable to load the requested file: taurus.jpeg

<image src="./applications/views/uploads/image.jpeg" />
By default, CodeIgniter denies access to the application folder which is why I suspect this isn't working.
$this->output->set_header("Content-Type: image/jpeg");
$data['image'] = $this->load->file('../uploads/taurus.jpeg');
I suspect this isn't working because your path is incorrect. The path is relative to the index.php file in the root of your application, not the file this code is in. Secondly, $this->load->file() sends to file contents to the browser so this wouldn't work anyway.
A solution would be to move your uploads folder to a web accessible location. For example, place the uploads folder into the root of your application - the same folder as your index.php file. Then you can display your image like this:
<image src="/uploads/image.jpeg" />

Just get rid of the dot (.) in the URL so your src url reads: "/applications/views/uploads/image.jpeg"

Related

Codeigniter: Make uploads accessible

I'm using the upload class to allow users uploading file to the server.
Those files (e.g. profile images) should be accessible in the browser. Right now, the files stored under /application/uploads which of course cannot be accessed via browser.
Is there a way to make those uploaded files accessible via htaccess?
The only way I can think of, would be moving the files into the /public folder after being uploaded to /application/uploads
What's the best case to handle this?
your folder structure should be like :
---application
--- controllers
--- helpers
--- views
---asset
---system
---uploads
And Whenever you want to fetch/show image use
<img src="<?php echo base_url('uploads/'); ?>" >
Save the files in outside i.e. in public/uploads folder
Create .htaccess file in that folder
Add following line to .htaccess to secure the folder
Options -Indexes

Error displaying images in subdomain using laravel 5.3

I have successfully deployed my laravel project to shared hosting (cPanel) and all seems to be working apart from the images. The images stored directly on the server e.g. logo.png don't show up and yet css files in the same public directory show up.
When I try to view the image directly via its URL, I still can't access it and gives me an error of "The image "http://..." cannot be displayed because it contains errors.
Could you please advise? Thanks in advance
Updated:
I have tried several alternatives which work locally but not when I upload.
< img src="/img/logo.png" width="100" />
< img src="{{ asset('/img/logo.png') }}" width="100" />
None of the above works and even when I try to access it via http://sub.domain.com/img/logo.png . It gives the error above
It turns out that the problem wasn't with the RewriteRule but rather the ftp client uploading the images with ASCII format. Laravel doesn't seem to pick those images so I re-ftped them with binary format and everything is working fine.
I hope this can help someone else.

Can not display the image which its path comes from database

I have a form which successfully upload a picture to a folder and save its full path to database.But when I want to display the image nothing is shown.
This is one of the uploaded image's path in database:
/home/webuser/public_html/traincms/upload/koala.jpg
this image saved in a folder of server.what should I do to display the images?
Thanks for your help.
You should use HTTP path of image, if you are using codeigniter then try this way
<?php echo img("traincms/upload/koala.jpg"); ?>
OR
<img src="<?php echo base_url("traincms/upload/koala.jpg")?>" />
Hope your code will store in public_html directory
Finally I found the solution.My upload path was
$path=dirname($_SERVER['SCRIPT_FILENAME']).'/upload/';
I saved this path to database.When I want to display the image on browser it did not display it with this path.I uploaded the image with above path but I saved this path to database:
$image_path=base_url().'/upload/'.$_FILES['pic']['name'];
now I can upload and display the images successfully.

How do I use relative http urls for Xaml images

I have a need to treat an image in XAML as a special case and have it download the image using the relative HTTP URL and not the relative DLL path. But I cannot seem to get that to work properly. I've tried the pack URL, but it seems to ignore it. None of these appear to work.
<Image Source="pack://siteoforigin:,,,/images/logo.png" />
<Image Source="~/images/logo.png" />
<Image Source="/images/logo.png" />
I would simply like these to work like ordinary HTML img src. I know I can do this in code, but I'm hoping to avoid that if I can.
I finally found a way to get this to work. My xap file is loaded from /ClientBin/, so the resulting URLs for the download are actually this:
/ClientBin/images/logo.png.
Once I realized that was happening, I was able to add URL map to my web.config and an HttpHandler to redirect the image download where I need it to go.

where should I add external file to view in CI

I'm trying to make view page in CodeIgniter,So I create it and in Controller it loads complete.
but when I add images and jQuery to it,they will not be loaded.
I made sub folder in view folder by name of Files and add to view for e.g like that
img src="Files/01.jpg" but it will not be shown.
where should I place them?
I usually make a folder called files in the main directory (where system and application reside), and then link to them using base_url().
In your case, this would become
<img src="<?= base_url(); ?>/files/01.jpg" />
Hope that helps.
When your view loads, the file paths will be relative to the directory the CodeIgniter index.php file is located in. If this is also the root directory of your site, you can refer to it in this way: <img src="/Files/01.jpg" />

Resources