我的网站允许用户将声音文件上传到服务器。用户注册时创建的目录(如用户名)。
mkdir("speaking/uploads/".$myusername,0777);
当用户要登录时:
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
$_SESSION['myusername'] = $myusername;
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and pass='$mypassword'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
if($count==1){
header("location:index.php");
}
else {
echo "Wrong Username or Password";
}
我想上传的文件去他的文件夹,但文件去上传目录。
<?php
$uploads_dir = './uploads/'.$_SESSION['myusername'];
if( $_FILES['Filedata']['error'] == 0 ){
if( move_uploaded_file( $_FILES['Filedata']['tmp_name'], $uploads_dir.$_FILES['Filedata']['name'] ) ){
echo 'ok';
exit();
}
}
echo 'error';
exit();
?>
请问这个怎么做?有没有更好和安全的想法来做到这一点?