如何从具有本地主机地址的远程服务器访问文件 [英] How to access a file from remote server which has a localhost address

查看:489
本文介绍了如何从具有本地主机地址的远程服务器访问文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友

我正在使用localhost,并且编写了将图像文件上传到ima​​ges目录,然后将其地址存储到数据库的函数.

在将网站启动到远程服务器之前,我必须上传大约1000张图像.但是问题是如果我在localhost上工作时上传这些图像,则所有图像都具有localhost的地址.但是,当我将站点启动到任何托管服务器时,我将如何访问这些映像,因为它们在数据库中都具有localhost的地址.

例如:
当我上传在本地主机上工作的图像时,其地址将是这样

Dear Friends

I am using localhost and I have written a function which uploads the image file to images directory and then store its address to the database.

I have to upload about 1000 images before launching my site to remote server. But the problem is if I upload these images while working on localhost then all the images have the address of localhost. But When I will launch my site to any hosting server, how I will access these images because they all have the address of localhost in database.

For example:
when i upload image working on local host its address will be like that

"http://localhost/images/file.jpg"



当我将网站启动到实际的托管服务器时,我将如何访问此文件.

请在这种情况下帮助我.



How I will access this file, When I will launch my web to actual hosting server.

Plz Help me in this situation.

推荐答案

这没有任何意义.图片没有地址.如果将映像存储在数据库中,则它们的来源无关紧要,除非出于某种愚蠢的原因也将"localhost"地址存储在数据库中.

或者,如果您仅将映像文件的路径存储在磁盘上,那么您现在就遇到了问题.您不应该设置文件路径的地址部分.您应该只存储文件在磁盘上的相对路径.然后,在检索图像文件时,可以使用已知目录路径和数据库中存储的相对路径来构建完全限定的路径.
This doesn''t make any sense. Images do not have addesses. If you stored the image in the database, it doesn''t matter where they came from, unless you stored the "localhost" address in your database too for some stupid reason.

Or, if you only stored the path to the image FILES on disk, now you''ve got a problem. You should not have sotred the address portion of the path to the file. You should have stored just the relative path to the location of the file on disk. Then, when retrieving the image file, you build the fully qualifed path using known directory paths and the relative path stored in the database.


这篇关于如何从具有本地主机地址的远程服务器访问文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆