我的文件没有使用mkdir移动到指定的和新创建的文件夹

时间:2010-07-13 15:54:49

标签: mkdir

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

希望我没有混淆任何人,但我真的需要帮助。

以下是我写的脚本。

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

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"; 
}

1 个答案:

答案 0 :(得分:1)

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

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

到此:

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