473,508 Members | 2,263 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using jS to display an image from file

The following test page is intended to allow the user to choose an image
file, and then display it. It works as expected in Safari 3.1.1, FF
2.0.0.14 (Mac), and IE7 (XP).

But, it fails in FF 2.0.0.14 (Win-XP) - the image doesn't appear. The
error console shows no errors and Page Info, under the media tab, shows
no loaded image (in contrast to FF Mac which shows the image).

The images I select are all jpegs, btw.

Any pointers would be appreciated - thanks.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/REC-html40/strict.dtd">

<html>
<head>
<title>Image with a Javascript preview.</title>
<script type="text/javascript">
function preview()
{
var filename = document.form1.filesent.value;
var Img = new Image ();
Img.src = filename;
document.images[0].src = Img.src;
alert ("Filename: '" + filename + "' width: " + Img.width + "
height: " + Img.height);
}

</script>
</head>

<body>
<h3>File Upload - v020</h3>
<form name='form1'>
<input type=file name=filesent>
<input type=button value="Preview" name="Preview" onClick="preview()">
</form>
<p>Image follows</p>
<img name="image1">
</body>
</html>
Jun 27 '08 #1
2 8310
Tim Streater escribió:
var filename = document.form1.filesent.value;
var Img = new Image ();
Img.src = filename;
A string like "C:\Picture.jpg" is not a valid URI. Try adding a
"file://" prefix and maybe escaping file name characters that need so.

--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño María: http://www.demogracia.com
--
Jun 27 '08 #2
VK
On May 21, 8:28 pm, Tim Streater <tim.strea...@dante.org.ukwrote:
The following test page is intended to allow the user to choose an image
file, and then display it. It works as expected in Safari 3.1.1, FF
2.0.0.14 (Mac), and IE7 (XP).

But, it fails in FF 2.0.0.14 (Win-XP) - the image doesn't appear. The
error console shows no errors and Page Info, under the media tab, shows
no loaded image (in contrast to FF Mac which shows the image).

The images I select are all jpegs, btw.

Any pointers would be appreciated - thanks.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/REC-html40/strict.dtd">

<html>
<head>
<title>Image with a Javascript preview.</title>
<script type="text/javascript">

function preview()
{
var filename = document.form1.filesent.value;
var Img = new Image ();
Img.src = filename;
document.images[0].src = Img.src;
alert ("Filename: '" + filename + "' width: " + Img.width + "
height: " + Img.height);
}

</script>
</head>

<body>
<h3>File Upload - v020</h3>
<form name='form1'>
<input type=file name=filesent>
<input type=button value="Preview" name="Preview" onClick="preview()">
</form>
<p>Image follows</p>
<img name="image1">
</body>
</html>
Within the standard security settings you are not allowed to read the
current input-file content, only the file name itself, without path.

IE and some other browsers are having a bit relaxed policy so they let
you to read the full path iff the current page is loaded from a local
drive. FF doesn't make such relaxation in neither case: this is why
the difference you see.

For a page loaded from the Web all browsers are acting in the same way
(file name only, no path) and sometimes even that is prohibited.

In any case no one browser will not let you to access the local file
system in the latter case, so even if you set the path manuially like
myImg.src = "file:///C:/image.gif" if will not work.

So the starting idea was nice but it didn't account the necessarily
imposed security restrictions.

For the preview if you still want to implement it, you have to submit
the image first to the server and having server bouncing the image to
the form's target (i)frame.
Jun 27 '08 #3

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

Similar topics

4
2702
by: Japhy | last post by:
Hello, I'm am pulling data from a mysql db and want to use the data to populate a <ul. Here are relavent parts of my code : $wohdate = mysql_result($wohRS,$wohndx,woh_date); $woh_display...
4
8363
by: Kevin Myers | last post by:
Hello, Please forgive my reposting of this note with hopefully a more relevant subject line. On an Access 2000 form under Windows 2000 I would like to use a Kodak Image Edit Control to...
1
2664
by: bborden | last post by:
Novice Access programmer here. I would like to display an image using the Toolbox Image object by calling the images file name using: =fPictureFiles(!!,1) in the Picture control. Below...
16
2006
by: Giggle Girl | last post by:
Hi there, I have a nav tree similar to the XP Windows Explorer in behavior. It uses styles to underline a row on mouseover, and change the look of a row when clicked. Currently, it is working...
3
5224
by: den 2005 | last post by:
Hi everyone, Here is code working on..Trying to insert record with a column with Image or VarBinary datatype in sql database from a existing jpeg image file, then retrieve this image from...
53
4597
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,...
0
1356
by: krishnasamy | last post by:
Hello, I am writing a DLL for Capturing the Image from Camera Device using Camera SDK DLL. All the calls made to functions in Camera SDK DLL are working properly as I am able to get a return...
2
16606
by: smorrison64 | last post by:
I have a form that is coded to open a File Dialog boc to pick a picture to display on that particular item on a subform. My form is not based on query, but rather two separate tables (one primary,...
1
2970
by: amritranjan | last post by:
How to retrive image file from MS access database and display this in another JSPpage -------------------------------------------------------------------------------- This is my Jsp code for...
3
2832
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
7231
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
1
7063
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7504
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5640
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4720
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3211
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3196
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1568
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
432
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.