0

所以我有一个问题。当有人在我正在构建的网站上注册一个帐户时,他们会转到一个设置页面,在那里他们可以上传个人资料图片。我正在使用 mkdir 使用他们的用户名自动创建一个工作正常的子文件夹,并且该子文件夹上的 CHMOD 为 777。我遇到的问题是图像没有被移动到那个指定的子文件夹,而是进入它的父目录的“上传”文件夹。

希望我没有让任何人感到困惑,但我真的需要帮助。

下面是我为此编写的脚本。

==================================================== ==============================

require_once('../admin/includes/config.php');

$uploaded_file = $_REQUEST['uploaded_file'];
$member_id = $_REQUEST['member_id'];
$name = $_REQUEST['name'];
$location = $_REQUEST['location'];
$hobbies = $_REQUEST['hobbies'];
$hobby = $_REQUEST['hobby'];

// using member_id, extract the username from the members table so we can auto create a sub-directory for the images

$result = mysql_query("SELECT username FROM members WHERE member_id = '$member_id'");

while($row = mysql_fetch_array($result))
  {
  $username = $row['username'];
  }

// unmask to change CHMOD of newly created sub directory to 777
$old_mask = umask(0);

//Create directory with member's username

$madedir = mkdir('../admin/uploads/'.$username.'', 0777) /*== TRUE ? 1 : 0*/;
umask($old_mask);


// Assign the directory the file is going to be uploaded to

$uploaddir = '../admin/uploads/'.$username.'';


// Get the file name

$file_name = $_FILES['uploaded_file']['name']; 


// Upload file to assigned directory with file name

$uploadfile = $uploaddir . basename($_FILES['uploaded_file']['name']);


// If the file has been uploaded, run this script

if (move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $uploadfile)) {

echo "Success";
} // end if
else {
echo "there was an error uploading your file"; 
}
4

1 回答 1

1

您似乎/在上传目录的末尾缺少 a 。改变这个:

$uploaddir = '../admin/uploads/'.$username.'';

对此:

$uploaddir = '../admin/uploads/'.$username.'/';
于 2010-07-13T15:58:52.853 回答