dongri1989 2011-11-30 03:29
浏览 41
已采纳

php中move_uploaded_file的目标路径

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)

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

In add-photo-submit.php, I have the following line of code:

$target_path = "uploads/" . basename($_FILES['uploadedFile']['name']);

$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

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...

In the future I would like my root directory to be setup like this:
root
 -admin (folder)
    -add-photo-submit.php
 -uploads

What frame of reference does move_uploaded_file have?

  • 写回答

4条回答 默认 最新

  • doujiku1028 2011-11-30 03:43
    关注

    You should use document_root to get absolute path like this:

    $target_path = $_SERVER['DOCUMENT_ROOT'] . "/uploads/" . basename($_FILES['uploadedFile']['name']);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 fesafe材料库问题
  • ¥35 beats蓝牙耳机怎么查看日志
  • ¥15 Fluent齿轮搅油
  • ¥15 八爪鱼爬数据为什么自己停了
  • ¥15 交替优化波束形成和ris反射角使保密速率最大化
  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统