php中move_uploaded_file的目标路径 [英] destination path for move_uploaded_file in php
问题描述
我需要知道将什么用于PHP的move_uploaded_file函数的目标路径. (请参见 http://php.net/manual/en/function.move -uploaded-file.php )
I need to know what to use for a destination path for PHP's move_uploaded_file function. (see http://php.net/manual/en/function.move-uploaded-file.php)
现在,我的代码工作正常.我域的根目录包含以下各项(包括其他各项):
上传 <-这是一个文件夹
add-photo-submit.php <-这是一个使用move_uploaded_file
Right now, I have code that works fine. My domain's root directory contains the following items (among others):
uploads <-this is a folder
add-photo-submit.php <-this is a PHP file that uses move_uploaded_file
在add-photo-submit.php中,我有以下代码行:
In add-photo-submit.php, I have the following line of code:
$target_path = "uploads/" . basename($_FILES['uploadedFile']['name']);
$ target_path用作函数的目标参数. 当我通过www.mydomain.com/add-photo-submit.php访问文件时,此方法就可以正常工作
$target_path is used as the destination parameter for the function. This works just fine when I access the file through www.mydomain.com/add-photo-submit.php
但是,我最近更改了.htaccess文件,以删除.php并添加斜杠. 现在,可以从www.mydomain.com/add-photo-submit/访问PHP文件. 我认为PHP文件将目标路径解释为"www.mydomain.com/add-photo-submit/uploads/filename.jpg"
However, I recently changed the .htaccess file to remove the .php and add a trailing slash. Now the PHP file is accessed at www.mydomain.com/add-photo-submit/ I think the PHP file is interpreting the target path as "www.mydomain.com/add-photo-submit/uploads/filename.jpg"
我尝试使用绝对路径,但是它说我没有权限...
I tried using an absolute path, but it said I didn't have permission...
将来,我希望像这样设置我的根目录:
根
-admin(文件夹)
-add-photo-submit.php
-上传
In the future I would like my root directory to be setup like this:
root
-admin (folder)
-add-photo-submit.php
-uploads
move_uploaded_file有什么参照系?
What frame of reference does move_uploaded_file have?
推荐答案
您应使用document_root来获取绝对路径,如下所示:
You should use document_root to get absolute path like this:
$target_path = $_SERVER['DOCUMENT_ROOT'] . "/uploads/" . basename($_FILES['uploadedFile']['name']);
这篇关于php中move_uploaded_file的目标路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!