473,569 Members | 2,688 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.getEle mentById('Pictu reToDisplay').s rc =
URLtoPictureOnW ebServer.src;

I cant get it to work with:

document.getEle mentById('backg roundLayer').sr c =
PathToPictureOn LocalDrive.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.setbackgr oundimage="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 2118
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.getEle mentById('Pictu reToDisplay').s rc =
URLtoPictureOnW ebServer.src;

I cant get it to work with:

document.getEle mentById('backg roundLayer').sr c =
PathToPictureOn LocalDrive.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.setbackgr oundimage="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.getEle mentById('Pictu reToDisplay').s rc =
URLtoPictureOnW ebServer.src;

I cant get it to work with:

document.getEle mentById('backg roundLayer').sr c =
PathToPictureOn LocalDrive.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.setbackgr oundimage="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
3665
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? When? Why? Thanks you for your answers.
2
7170
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 if it's a physical memory constraint then I think I am away from that. I am trying to cache about 600K images, (this if for an intranet so the page...
22
3076
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 to be doing so in practice. Any idea where Im going wrong? Could it be that things work differnetly when in an attached .js file? -- --
4
12223
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 view found in Microsoft SQL Server Enterprise Manager. So we have Server Groups and Servers, in the tree view. I want to create my own similar...
3
2219
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 improve the performance, I want these images to reside on the RAM instead of the hard disk. How do I load the images to the ram and access it to...
3
3455
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. -Regards Arun
9
2360
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!!! Cheers,
2
1776
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 is being run. Can someone help me understand the behaviour described below and offer a suggestion as to how to tune this ? Your assistance is...
1
1361
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 Application through internet.But we planned to give 'local Hard disk' backup , where user can download my application to their local hard disk and...
0
7703
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7926
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8138
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7679
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7983
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5223
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3647
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1228
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
946
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.