473,320 Members | 1,953 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Using file:// for an image

I am trying to do something seemingly difficult. I am trying to take the
value from a file input and set the source of an image to the value of the
file input. It seems to only work on Safari. In FF I can do it and then when
viewing the rendered chart I see the image is there with the correct path
and all. For example file:///Users/me/desktop/1234.jpg Is this a security
thing? I can have multiple images from multiple domains on a page but not
one from the users hd. Confusing? Here is a sample of the code:

<img src="" id="preview">

<input type="file" name="test"
onchange="document.getElementById('preview').src = ('file://'+this.value);">
Again, this works in Safari perfectly. In FF I can view the source chart and
it has the correct path. Just not displaying. I even tried using the DOM to
create a new image and plant it on the page. The image is there but not
displayed. Is there a work around for this?

-S

Jun 4 '06 #1
2 1276

Phat G5 (G3) wrote:
I am trying to do something seemingly difficult. I am trying to take the
value from a file input and set the source of an image to the value of the
file input. It seems to only work on Safari. In FF I can do it and then when
viewing the rendered chart I see the image is there with the correct path
and all. For example file:///Users/me/desktop/1234.jpg Is this a security
thing? I can have multiple images from multiple domains on a page but not
one from the users hd. Confusing? Here is a sample of the code:
...


Yes, this is a security thingie. JavaScript is kept away from file
uploads to keep someone from emailing themself /etc/passwd or whatever,
and most vendors extended that to include all file uploads. How reading
an uploaded file is unsafe I don't know or understand, though. A simple
alternative would be to have your file upload form in an iframe, and
have the PHP return a simple page that does nothing but run some JS to
set your <img>'s src attribute.

Simple.

Jun 4 '06 #2
Phat G5 (G3) wrote:
I am trying to do something seemingly difficult. I am trying to take the
value from a file input and set the source of an image to the value of the
file input. It seems to only work on Safari. In FF I can do it and then when
viewing the rendered chart I see the image is there with the correct path
and all. For example file:///Users/me/desktop/1234.jpg Is this a security
thing? I can have multiple images from multiple domains on a page but not
one from the users hd. Confusing? Here is a sample of the code:

<img src="" id="preview">

<input type="file" name="test"
onchange="document.getElementById('preview').src = ('file://'+this.value);">
Again, this works in Safari perfectly. In FF I can view the source chart and
it has the correct path. Just not displaying. I even tried using the DOM to
create a new image and plant it on the page. The image is there but not
displayed. Is there a work around for this?


A security thing. See
http://www.mozilla.org/projects/secu...firefox1.5.0.4
and then the link for MFSA 2006-39 for some partial info on it.

I'm guessing that the reasons for not allowing this are that the files
could have malicious code embedded (but I'd think that would be the
responsibility of the individual components to deal with) and more
importantly, that you could possibly guess at the files/directory
structure on the user's machine.

Csaba Gabor from Vienna

Jun 4 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Randell D. | last post by:
HELP! Its taken me ages - I'm a newbie and I've compiled bits of code that I've read in this newsgroup over time to create one of my most intricate functions to date... Basically, the script...
0
by: Nicolas Guilhot | last post by:
Hi all ! I have a multi-page Tiff image file that I want to convert to PDF. To do so I am using iText library. The conversion is working, but the code execution is very different according to...
7
by: Nilesh | last post by:
I am using background-image attribute in a CSS file and linking the CSS file to aspx page. But strangly, background-image attribute is not working for relative URL. e.g. If I apply following css...
5
by: IkBenHet | last post by:
Hello, I use this script to upload image files to a folder on a IIS6 server: ******************* START UPLOAD.ASPX FILE ********************** <%@ Page Language="VB" Debug="true" %>
53
by: Hexman | last post by:
Hello All, I'd like your comments on the code below. The sub does exactly what I want it to do but I don't feel that it is solid as all. It seems like I'm using some VB6 code, .Net2003 code,...
2
by: prakharv | last post by:
Hi All, Below is the code which I am using to upload a jpeg file to the server. But the problem I am facing is that it is not copying the entire contents of the image file to the webserver and it...
1
by: snitu | last post by:
hello i am new to using javascript. i have a problem in creating texonomy using xml file in javascript. my xml file is this ________________________________________ <?xml version="1.0"?>...
7
by: snitu | last post by:
hello i am new user of this forum. i have a problem in javascript code. plz. give me idea about how to create tree using xml file (not using xsl file) in javascript. i am also sending my...
3
by: kksandeep | last post by:
i am using this three files to uplod file. i got this file from net but i think these have some error. i am new to this field plz help the script i found is some helpful but not too that i need ...
3
by: =?Utf-8?B?QmlsbHkgWmhhbmc=?= | last post by:
I have a asp.net app, in the page there is a scan activex which could scan and save a jpg file in client harddisk. How could we access and display this jpg file on the fly using js in the client...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.