wp,sql,文件夹中的图像未显示但在数据库中..输入

时间:2012-09-14 09:06:36

标签: mysql wordpress-plugin

$uploadDir = 'images/';
$fileName = $_FILES['Photo']['name'];
$tmpName = $_FILES['Photo']['tmp_name']; 
$fileSize = $_FILES['Photo']['size']; 
$fileType = $_FILES['Photo']['type'];
$filePath = $uploadDir . $fileName; 
$result = move_uploaded_file($tmpName, $filePath);

1 个答案:

答案 0 :(得分:0)

move_uploaded_file()手册页上的commented by Darrel

  

move_uploaded_file apparently uses the root of the Apache installation (e.g. "Apache Group\Apache2" under Windows) as the upload location if relative pathnames are used.

For example,
$ftmp = $_FILES['userfile']['tmp_name'];
$fname = $_FILES['userfile']['name'];
move_uploaded_file($ftmp, $fname);
                          
moves the file to
"Apache Group\Apache2\$fname";

In contrast, other file/directory related functions use the current directory of the php script as the offset for relative pathnames.  So, for example, if the command

mkdir('tmp');

is called from 'Apache Group\Apache2\htdocs\testpages\upload.php', the result is to create
'Apache Group\Apache2\htdocs\testpages\tmp'

On the other hand, if 'mkdir' is called just before 'move_uploaded_file', the behavior changes.  The commands,

mkdir('tmp');
move_uploaded_file($ftmp, $fname);

used together result in

"Apache Group\Apache2\htdocs\testpages\tmp\$fname"

being created.  Wonder if this is a bug or a feature.