2
我想爲Zend_File_Transfer_Adapter_Http
對象手動設置name
,type
,size
,是否有可能?是否可以設置Zend File Transfer Adapter的名稱,類型和大小?
我想爲Zend_File_Transfer_Adapter_Http
對象手動設置name
,type
,size
,是否有可能?是否可以設置Zend File Transfer Adapter的名稱,類型和大小?
絕對。但是你的陳述中有一些混淆。我想你的意思是限制上傳文件的類型和大小,否則你可以用名稱「sampleFile.ext」輕鬆創建一個文件,並用特定大小的空格填充內容,我看不到任何東西雖然有用。
開始一個新的對象:
$uploaded_file = new Zend_File_Transfer_Adapter_Http();
文件大小驗證:
// Set a file size with 20000 bytes
$upload->addValidator('Size', false, 20000);
// Set a file size with 20 bytes minimum and 20000 bytes maximum
$upload->addValidator('Size', false, array('min' => 20, 'max' => 20000));
// Set a file size with 20 bytes minimum and 20000 bytes maximum and
// a file count in one step
$upload->setValidators(array(
'Size' => array('min' => 20, 'max' => 20000),
'Count' => array('min' => 1, 'max' => 3),
));
擴展驗證:
// Limit the extensions to jpg and png files
$upload->addValidator('Extension', false, 'jpg,png');
// Limit the extensions to jpg and png files but use array notation
$upload->addValidator('Extension', false, array('jpg', 'png'));
// Check case sensitive
$upload->addValidator('Extension', false, array('mo', 'png', 'case' => true));
if (!$upload->isValid('C:\temp\myfile.MO')) {
print 'Not valid because MO and mo do not match with case sensitivity;';
}
排除的文件擴展名驗證:
// Do not allow files with extension php or exe
$upload->addValidator('ExcludeExtension', false, 'php,exe');
// Do not allow files with extension php or exe, but use array notation
$upload->addValidator('ExcludeExtension', false, array('php', 'exe'));
// Check in a case-sensitive fashion
$upload->addValidator('ExcludeExtension',
false,
array('php', 'exe', 'case' => true));
$upload->addValidator('ExcludeExtension',
false,
array('php', 'exe', 'case' => true));
要更改文件名,請使用過濾器:Zend_File_Transfer_Http How to set uploaded file name
我不知道你這是什麼意思。這些參數應該在傳輸開始的文件上傳表單中進行設置。 –