0

I have a website hosted in LAMP Server. My Lamp server is installed in a Debian virtual machine. My virtual machine is hosted in a distant server.

I face a problem when i try to display an image in my website from the distant server. this is an example of the code i am using :

src="\\NameOfDistantServer\Directory\MyImage.jpg"

When i try this code, nothing is displyed.

I need your help.

Thank you

Nikhil Vaghela
  • 2,088
  • 2
  • 15
  • 30
  • If the code and image is on same server use a local path like `src="images/myimage.jpg"` the src param does not need the `http://servername` just a valid local path. It shoudl also be relative to where the PHP code file is in relation to the image file – RiggsFolly Aug 09 '16 at 09:46

3 Answers3

0

I'm pretty sure it should be something like:

src="http://NameOfDistantServer/Directory/MyImage.jpg"

You need to specify the http, otherwise the browser thinks the file is on the same server as the html page. You need the / slashes because that's what most web servers understand.

Ben Hillier
  • 2,126
  • 1
  • 10
  • 15
0

If I really understand your question, you have a linux webserver and you want to embed an image from your server inside a HTML file.

When you wrote src="\NameOfDistantServer\Directory\MyImage.jpg", you should add slashes instead of backslashes even if most browsers changes them correctly.

Asyour question is a bit unclear, I will show you most used methods of embedding images on a webpage.

1. Specify full URL of the image:

If you want to specify full url, your code should be like this:

<img src="http://yourdomainname.something/directory/yourimage.jpg"/>

2. Specify a relative URL of the image:

If your image is hosted for example, at: http://example.com/directory/test.png, and you want to print that image still on the same domain (example.com), you can specify the relative path of the image, not the entire path:

<img src="/directory/test.png"/>

3. Encode images to base64 to not use files

If you don't want to host the image inside a file on your server, you can covert it to base64 and embed it on your webpage as a code, instead of file url. For this, you can use our service which is converting the image you choose to an encoded image: http://netcreator.us/base64-image-encode

  • Hi ! first of all i'd like to thank you for your very clear answers, at least now i have an error like : net::ERR_CONNECTION_REFUSED , the access to the distant server need a login and a password, i think i should add my virtual machine as a user of the distant server to have an access to the images directory. – Mehdi Semlali Aug 09 '16 at 11:37
  • @MehdiSemlali, sorry for the delay. You're welcome! Please tell me more about. If I correctly understand, when you try to open the image directly (eg: http://example.com/directory/image.jpg) in your browser, then it prompts to add username and password? – NETCreator Hosting - WebDesign Aug 10 '16 at 10:01
  • I really appreciate your help, actually what i did i've created a new directory in the distant server reachable for all users (it means that no one need to login to reach the directory) and i put an image in this directory, i double checked that the image is reachable by all users, (right click, property, security) and when i try to display the image in the website, the console gives an error : net::ERR_CONNECTION_REFUSED I tried all of the solutions you have mentioned in your answer above. – Mehdi Semlali Aug 10 '16 at 11:52
  • Can you please provide me the url of the image (eg: `http://example.com/directory/image.jpg`) as to give you the correct code to embed that image? Would be much simple. If the image is reachable on the web (while opening on browser), it should be embeddable. – NETCreator Hosting - WebDesign Aug 10 '16 at 15:23
  • Yes of corse, this my code : . serverintranet1 is the server where all the data of the compagny is stored...test is the directory i created with all permissions for all users. My code + Apache server is in a Virtual machine connected to the intranet. So when i am connected to the intranet of the company i can easly reach the photo by opening a browser and using this url [link](file://serverintranet1/test/photo.jpg ). – Mehdi Semlali Aug 11 '16 at 08:05
  • @MehdiSemlali Unfortunately, you can't embed an image using `file://` protocol, on a live website. You can use it only locally. You can read more about, here: http://superuser.com/questions/224500/how-to-display-local-images-in-chrome-using-file-protocol. An image can be embedded using `http`, `https`, `ftp`, `ftps` or `sftp` protocol. I'd recommend you to create a FTP account on the external server (without username and password, or maybe just username) and then embed the image using: `` – NETCreator Hosting - WebDesign Aug 12 '16 at 07:35
  • or `` if using an username. IMPORTANT: When creating the FTP account, please don't forget to specify account permissions ONLY TO READ/VIEW files, NOT to write, modify or delete as to avoid getting all your files deleted by a website user. – NETCreator Hosting - WebDesign Aug 12 '16 at 07:37
0

The only way i found to resolve my problem was to do mount command :

mout -t cifs /serverDistant/directoryToshare /directory username pwd

After this command i can display all the image like if it was on local directory. Thank you all for your suggestions, i really appreciate your help.