简体   繁体   English

在Web服务器中上传的文件路径

[英]file path for uploading in web server

I'm very new in web developing. 我是Web开发领域的新手。 I'm developing a website by using HTML, jQuery, JavaScript, PHP and MySql. 我正在使用HTML,jQuery,JavaScript,PHP和MySql开发网站。 On my website I have an option for uploading images, and I'm using this code: 在我的网站上,我可以选择上传图片,并且正在使用以下代码:

move_uploaded_file(
    $_FILES["file"]["tmp_name"],
    "c:/wamp/www/upload/upload/" . $_FILES["file"]["name"]
);

This code is for moving the image to c:wamp/www/upload/upload/ . 该代码用于将图像移动到c:wamp/www/upload/upload/ How can I achieve this on web server after hosting my website? 托管网站后,如何在Web服务器上实现此目的?

when you upload your files in the local , do not give "c:/wamp/www" . 当您在本地上传文件时, do not give "c:/wamp/www" Instead give the path relative to the file, like "../upload/" . 而是提供相对于文件的路径,例如"../upload/"

For example if you have placed your php script file in "upload/include/" folder and you would like to upload an image in "upload/images/" folder, use "../images/" while uploading the files. 例如,如果您已将php脚本文件放置在"upload/include/"文件夹中,而您想在"upload/images/"文件夹中上传图像,则在"upload/images/"文件时使用"../images/"

Does your web host provide shared or dedicated hosting? 您的网络托管服务商是否提供共享或专用托管服务?

I'm guessing shared, and so you'd probably have a directory path like /htdocs/upload or something similar. 我猜是共享的,所以您可能会有一个目录路径,例如/ htdocs / upload或类似的目录。 Hard to say without knowing what your web host is like. 不知道您的虚拟主机是什么样子就很难说。

simply give path of that folder.suppose the upload folder in the same directory of your uploading file script than you have to do just like that: 只需给出该文件夹的路径即可,假设上传文件夹与您的上传文件脚本位于同一目录中,而不必像这样:

move_uploaded_file($_FILES["file"]["tmp_name"],
                            "upload/" . $_FILES["file"]["name"]);

and if if it is out side of the script file than just use this 如果它不在脚本文件之外,则仅使用此命令

move_uploaded_file($_FILES["file"]["tmp_name"],
                                "../upload/" . $_FILES["file"]["name"]);

Hence no need to give path from root. 因此,无需给出从根开始的路径。

Use $_SERVER['DOCUMENT_ROOT'] for the dynamic path retrieval. 使用$_SERVER['DOCUMENT_ROOT']进行动态路径检索。

Try this, 尝试这个,

move_uploaded_file($_FILES["file"]["tmp_name"],$_SERVER['DOCUMENT_ROOT']."upload/" . $_FILES["file"]["name"]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM