开发者

Local image displays in IE but not firefox?

开发者 https://www.devze.com 2023-01-06 19:24 出处:网络
I have the following line to display an image: $output .= \'<div><img src=\"C:/backup/images/000001_full.jpg\"></div>\';

I have the following line to display an image:

$output .= '<div><img src="C:/backup/images/000001_full.jpg"></div>';

($output is then put into an html file as a local backup).开发者_如何学JAVA When I view the page with IE, the image is displayed fine, but not with firefox. Any idea why?

Thanks,

Dave


I think you want:

$output .= '<div><img src="file://c:/backup/images/000001_full.jpg"></div>';


You need to close your img tag. So,

$output .= '<div><img src="C:/backup/images/000001_full.jpg" /></div>';

IE likes to play it kind of loose with HTML specs, but Firefox pays more attention to the standards.


Maybe because your src is not valid urlfor Firefox.
Have you tried file://c:/backup/images/000001_full.jpg ?


Why are you using a link to the file system location? The image should be part of the site, and should be linked to as a relative URL such as \images\000001_full.jpg.


use relative path. i am also not sure but Something like $output .= '<div><img src="../images/000001_full.jpg"/></div>'


I reproduced this problem. The image displays in IE (and Chrome), but not in Firefox. The reason is because local files can't be accessed directly. Prefix the src tag with file:/// and it will work just fine as in:

$output .= '<div><img src="file:///C:/backup/images/000001_full.jpg"></div>';


It is not straight forward in Chrome and firefox. Modern browsers due to security reasons do not allow you to show image from file system.

Steps: 1. set variable where your input type file is defined

HTML : <input type="file" id="image-input"/>
var fileInput = document.getElementById('image-input');
  1. Get temporary file URI:

    var uri = window.URL.createObjectURL(fileInput.files[0]); Pass this Uri to the image src from Javascript. Problem solved.

Follow this link for help: http://www.philliphaydon.com/2014/04/loading-an-image-or-video-from-a-file-input-control/

0

精彩评论

暂无评论...
验证码 换一张
取 消