我目前有一个数据库连接和一个配置文件模型。我可以像这样将用户名保存在控制器中
if(isset($_POST['action'])){
$user= $this->model('User');
$user->username= $_POST['username'];
如何将个人资料图片保存给该用户?我努力了
$file = $_FILES['file']; //get file
$file_name = $_FILES['file']['name']; //get file name
$file_tempDir = $_FILES['file']['tmp_name']; // temp name
$file_size = $_FILES['file']['size']; // file size
$file_errorMsg = $_FILES['file']['error']; // error msg
$file_type = $_FILES['file']['type']; //file type
$file_convertedExtension = strtolower(pathinfo($file_name, PATHINFO_EXTENSION)); // to lower to avoid upper case extensions
//Allow files to have the same name
$file_uniq = uniqid('', true). "." . $file_convertedExtension;
// Make sure extension is allowed*
if(in_array($file_convertedExtension, $possible_extensions)){
$file_saveDestination = '../images/' . $file_uniq;
move_uploaded_file($file_tempDir, $file_saveDestination);
}
else{
echo "This type of file extension is not allowed.";
}
$user->user_images= $file_uniq;
但这不起作用。$user->user_images = $_POST['file']似乎添加到数据库中,但我不知道它是否正确
还有 move_uploaded_file($file_tempDir, $file_saveDestination); 似乎没有在目的地保存任何东西