急!100分求``Zend_File_Transfer_Adapter_Http()上传图片问题

jekom 2009-07-27 12:35:10
$adapter = new Zend_File_Transfer_Adapter_Http();

$adapter->setDestination('./public/bigimg/');
$adapter->addValidator ( 'Extension', false, 'jpg,png,gif' )
->addValidator( 'Size', false, 1048576*2 )
->addValidator ( 'Count', false, array('min' => 1, 'max' => 3) );

if (!$adapter->receive()) {
$messages = $adapter->getMessages();
echo implode("n", $messages);
}
1,这样能够把图片上传到public/bigimg/这个文件夹中,但是我我想修改上传文件的文件名(如1.JPG,上传后改成200907026_1.JPG),请问能改吗?怎么改?

2,我想把同1张图片保存到2个不同的文件夹里,又怎么改呢?谢谢高手解答!
...全文
455 点赞 收藏 10
写回复
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
jekom 2009-07-30
$adapter = new Zend_File_Transfer_Adapter_Http();
//$adapter->setDestination('./public/bigimg');
$adapter->addValidator ( 'Extension', false, 'jpg,png,gif' )
->addValidator( 'Size', false, 1048576*2 )
->addValidator ( 'Count', false, array('min' => 1, 'max' => 3) );

$file = $adapter->getFileInfo();
$this->newname = time().'_'.$file['fichier']['name'];
$adapter->addFilter('Rename', "./public/bigimg/$this->newname");

if (!$adapter->receive()) {
$messages = $adapter->getMessages();
echo implode("\n", $messages);
}
=========================================================================
我这样写,同1张图片的传2次,才能传到"public/bigimg/"这个目录,而且改了名字,我检查到第1次传,他传到了C:\WINDOWS\Temp.这个目录,第2次才能到"public/bigimg/"这个目录
请高手解答下,解决马上放分!
回复
jekom 2009-07-29
$upload = new Zend_File_Transfer_Adapter_Http();
$upload->addFilter('Rename', array('source' => '/path/to/oldfile','target' => '/path/to/newfile', 'overwrite' => true));
=====================================================
不行,
回复
jekom 2009-07-28
2天了,就没人知道?
回复
jekom 2009-07-28
好的`我试下``
回复
程序猿之殇 2009-07-28
路径+文件名
你尝试一下喽.
手头上没有zend的框架,网上google的.
回复
jekom 2009-07-28
$upload = new Zend_File_Transfer_Adapter_Http();
$upload->addFilter('Rename', array('source' => '/path/to/oldfile','target' => '/path/to/newfile', 'overwrite' => true));
=======================================================
这个是手册上的,但是我有个疑问,'/path/to/oldfile'这个到底是路径还是,路径+文件名?
回复
程序猿之殇 2009-07-28
有高人,曾经在$adapter = new Zend_File_Transfer_Adapter_Http(); 之前,修改$_FILE数组,呵呵.
但正经的方式还是要用addFilter的.
回复
foolbirdflyfirst 2009-07-28
找找ZF api对应的addFilter方法,不行就用原始点的代码吧。

if(move_uploaded_file("tmp路径","路径+文件名")){
copy("路径+文件名","路径2+文件名2")
}
回复
程序猿之殇 2009-07-28
// Example for 1.6
$upload = new Zend_File_Transfer_Adapter_Http();
$upload->addFilter('Rename', array('/path/to/oldfile', '/path/to/newfile', true));
// Same example for 1.7
$upload = new Zend_File_Transfer_Adapter_Http();
$upload->addFilter('Rename', array('source' => '/path/to/oldfile', 'target' => '/path/to/newfile', 'overwrite' => true));
回复
jekom 2009-07-27
没人知道吗?
回复
发动态
发帖子
基础编程
创建于2007-09-28

2.1w+

社区成员

从PHP安装配置,PHP入门,PHP基础到PHP应用
申请成为版主
社区公告
暂无公告