我目前有数据库连接和配置文件模型。我可以将用户名保存在像这样的控制器中
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);似乎并没有在目的地保存任何东西