【发布时间】:2011-07-03 14:41:35
【问题描述】:
这是我的代码 -
<?php
session_start();
include('connect.php');
mysqli_select_db($connect, "users");
$s = "select * from name where sessionusername = '$u'";
$q = mysqli_query($connect, $s);
$f = mysqli_fetch_array($q);
$name = $f['name'];
if (!empty($_FILES)) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
$targetFile = str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];
// $fileTypes = str_replace('*.','',$_REQUEST['fileext']);
// $fileTypes = str_replace(';','|',$fileTypes);
// $typesArray = split('\|',$fileTypes);
// $fileParts = pathinfo($_FILES['Filedata']['name']);
// if (in_array($fileParts['extension'],$typesArray)) {
// Uncomment the following line if you want to make the directory if it doesn't exist
// mkdir(str_replace('//','/',$targetPath), 0755, true);
// Get the extension, and build the file name
//$extension = pathinfo($tempFile, PATHINFO_EXTENSION);
$extension = end(explode(".",$_FILES['Filedata']["name"]));
$new_file_name = '".$name."'".".$extension;
$targetFile = str_replace('//','/',$targetPath) . $new_file_name;
// $targetFile = str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];
move_uploaded_file($tempFile,$targetFile);
echo str_replace($_SERVER['DOCUMENT_ROOT'],'',$targetFile);
// } else {
// echo 'Invalid file type.';
// }
}
?>
为什么上述方法不起作用?如您所见,我试图从用户数据库中提取名称,然后将上传的文件重命名为从数据库中提取的名称。
你能帮帮我吗?非常感谢。
【问题讨论】:
-
哪个部分不工作?是否正在生成错误?文件是实际上传的还是空的?
-
文件未上传。错误 HTTP_ERROR。
-
请复制准确的错误信息。
-
确保您的表单具有正确的 enctype (multipart/form-data)