我使用 Zend_File_Transfer_Adapter_HTTP()
上传文件(图像),然后使用 Application_Model_DbTable_User()
更新 users
mysql 表文件对应的路径。
这是 Controller 中的操作:
public function profileAction() {
$form = new Application_Form_Updateprofile();
$users = new Application_Model_DbTable_User();
$session = new Zend_Auth_Storage_Session();
$adapter = new Zend_File_Transfer_Adapter_HTTP();
$loggedUser = $session->read()->username;
$this->view->form = $form;
if ($this->getRequest()->isPost()) {
$adapter->setDestination('ProfilePhotos');
$filename = pathinfo($form->image->getFileName());
$adapter->addFilter('Rename', uniqid() . '.' . $filename['extension']);
if (!$adapter->receive()) {
$messages = $adapter->getMessages();
echo implode("\n", $messages);
} else {
$userProfilePhoto = $adapter->getFileName('image');
$users->UpdateProfilePic($loggedUser, $userProfilePhoto);
}
}
}
这是 Zend_File_Transfer_Adapter_HTTP()
中的函数 UpdateProfilePic()
:
public function UpdateProfilePic($username, $img_address) {
$bind = array("profile_pic" => $img_address);
$where = "username = $username";
$this->_db->update($this->_name, $bind, $where);
}
Var_dump($用户名,$img_地址,$bind,$where) 输出:
$img_address - string(31) "ProfilePhotos\5429294234ebe.gif"
$username - string(7) "Tiberiu"
$bind - array(1) { ["profile_pic"]=> string(31) "ProfilePhotos\5429294234ebe.gif" }
$where - string(18) "username = Tiberiu"
用户
表:
CREATE TABLE `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`email` varchar(255) NOT NULL,
`username` varchar(30) NOT NULL,
`password` varchar(15) DEFAULT NULL,
`profile_pic` varchar(50) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `username` (`username`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1
这是我第一次尝试 Zend_File_Upload,虽然文件传输成功,但它不会更新 users
表,我不明白为什么,我检查了手册,我我认为我正在向 update()
操作提供正确的参数。
最佳答案
错误出现在我的数据库类中的 UpdateProfilePic()
函数中。
应该是:
$where = "`username` = '$username'";
而不是:
$where = "`username` = $username";
关于mysql - 即使参数正确,Zend update() 也会给出应用程序错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26096991/