473,396 Members | 2,129 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,396 software developers and data experts.

swapping images that are on local hard disk

Hi,

On my site the user can browse to an image with <input type=file etc>.
Althrough I have no problem swapping images with:

document.getElementById('PictureToDisplay').src =
URLtoPictureOnWebServer.src;

I cant get it to work with:

document.getElementById('backgroundLayer').src =
PathToPictureOnLocalDrive.src

I've tried hardcodeing the variable (with and without quotes) with all
the obvious values:
"C:\pics\mypic.jpg", "file:///c:/pics/mypic.jpg" etc etc but cant get
it to work.

Any ideas why its fine with remote pictures, but not with local ones?

(Also, just to muddy the waters even more, I've managed to display a
local image using a style.setbackgroundimage="path to local image", but
abandoned this as I cound not get the image to re-size :( )

Any help gratefully recieved

Regards

Eadmund

Dec 18 '06 #1
2 2101
TuftyTrue wrote:
Hi,

On my site the user can browse to an image with <input type=file etc>.
Althrough I have no problem swapping images with:

document.getElementById('PictureToDisplay').src =
URLtoPictureOnWebServer.src;

I cant get it to work with:

document.getElementById('backgroundLayer').src =
PathToPictureOnLocalDrive.src

I've tried hardcodeing the variable (with and without quotes) with all
the obvious values:
"C:\pics\mypic.jpg", "file:///c:/pics/mypic.jpg" etc etc but cant get
it to work.

Any ideas why its fine with remote pictures, but not with local ones?

(Also, just to muddy the waters even more, I've managed to display a
local image using a style.setbackgroundimage="path to local image", but
abandoned this as I cound not get the image to re-size :( )

Any help gratefully recieved

Regards

Eadmund
Hi,

AFAIK: What you want cannot be done with JavaScript.
Local filesystem is not accesible via a random webpage's JavaScript (which
is by design and good).
The only exception to that rule is a file-upload, but that is crippled too
so JavaScript cannot 'see' the values (files) used. (again by design).

Some/many browsers let you retrieve html-files from the local filesystem
(not via http), and then this restriction is lifted.
I think this is called 'same origin policy' or something like that.
So if the html-file originates from your local hd, the images can be found,
if the html-file originates from some website (via http) your local
filesystem is not accesible (not via a hardcoded link, and not via JS).

This is good. Think about what would happen if any webpage could browse your
filesystem behind your back...

I think the only way out is:
1) upload the file to the server
2) offer the page with the (freshly uploaded) backgroundimage coming from
the server (http).

Maybe you can lift this restriction via 'trusted zones' in IE. Don't know.

Just my 2 cent.

Regards,
Erwin Moller
Dec 18 '06 #2
Hi Erwin,

Thanks for the quick reply. I think your right, I'm going to have to
post the image the user has browsed to back to my site, then grab it
back from the server.

The irritating thing is that running the script while testing works
fine when run from my desktop. I can even get image attributes such as
hight and width and work out if its portrate and landscape and size my
display accordingly. It all goes south when I run it from my web
server, I'm assuming the browsers seurity contexts change somehow.

The really odd thing is that I can change an image to one the user has
browsed to by setting the backgroundLayer property, but as you cannot
re-size this is javaascript, its no good in my environment :(

Oh -well, back to perl side scripting again.....
Erwin Moller wrote:
TuftyTrue wrote:
Hi,

On my site the user can browse to an image with <input type=file etc>.
Althrough I have no problem swapping images with:

document.getElementById('PictureToDisplay').src =
URLtoPictureOnWebServer.src;

I cant get it to work with:

document.getElementById('backgroundLayer').src =
PathToPictureOnLocalDrive.src

I've tried hardcodeing the variable (with and without quotes) with all
the obvious values:
"C:\pics\mypic.jpg", "file:///c:/pics/mypic.jpg" etc etc but cant get
it to work.

Any ideas why its fine with remote pictures, but not with local ones?

(Also, just to muddy the waters even more, I've managed to display a
local image using a style.setbackgroundimage="path to local image", but
abandoned this as I cound not get the image to re-size :( )

Any help gratefully recieved

Regards

Eadmund

Hi,

AFAIK: What you want cannot be done with JavaScript.
Local filesystem is not accesible via a random webpage's JavaScript (which
is by design and good).
The only exception to that rule is a file-upload, but that is crippled too
so JavaScript cannot 'see' the values (files) used. (again by design).

Some/many browsers let you retrieve html-files from the local filesystem
(not via http), and then this restriction is lifted.
I think this is called 'same origin policy' or something like that.
So if the html-file originates from your local hd, the images can be found,
if the html-file originates from some website (via http) your local
filesystem is not accesible (not via a hardcoded link, and not via JS).

This is good. Think about what would happen if any webpage could browse your
filesystem behind your back...

I think the only way out is:
1) upload the file to the server
2) offer the page with the (freshly uploaded) backgroundimage coming from
the server (http).

Maybe you can lift this restriction via 'trusted zones' in IE. Don't know.

Just my 2 cent.

Regards,
Erwin Moller
Dec 18 '06 #3

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

Similar topics

4
by: cover | last post by:
The question is, we have two options to store images, either in a Database (MySQL, Postgres, ...) like blob data, or in the hard disk the file and the path in database. Which option is better?...
2
by: Dave Griffiths | last post by:
Hi all Very new to JavaScript, I am trying to cache a number of images as the page loads, is there a max number of images or memory usage before the browser stops caching. My PC has 1G ram so...
22
by: Fabian | last post by:
var preload1 = new Image(); preload1.src = "/pic/yay.gif"; var preload2 = new Image(); preload2.src = "/pic/nay.gif"; The above is meant to preload image files, yes? Problem is, it doesnt seem...
4
by: Mark Allison | last post by:
Hi, Newbie here, please bear with me. I have a C# project which implements a tree view control. I want to add some images to this tree view control. The tree view control represents the tree...
3
by: mraj | last post by:
Hello... I am new to C#. My requirement is that, I will receive over 100s of images from the network to local machine and display these images on an image viewer one by one on mouse scroll. To...
3
by: Arun | last post by:
Hi, I have simple question to ask. How to write multiple Binary files to the Browser using Asp.Net and Visual C#.net I have seen examples where single binary file is written to browser. ...
9
by: Adam J Knight | last post by:
Hi all, Just wondering whats everyones prefered method of storing images ? 1) File System 2) Database (SqlServer) (Seems to be easier, but has a performance hit) Appreciate some insight!!!...
2
by: mike_dba | last post by:
I have recently upgraded from SuSe 8 to 9 (kernel 2.4 to kernel 2.6). I am running DB2 8.1 FP 11 (aka 8.2 FP 4). I have had slowdowns that I suspect are related to the fact that an online backup...
1
by: suresh_nsnguys | last post by:
Hi Guys, I am working in a digital signage software where user can display ads in the LCD screen.MyApplication is running PHP & MySQL. Right Now users are accessing my...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.