Home Backend Development PHP Tutorial About the implementation method of renaming uploaded files in Zend Framework

About the implementation method of renaming uploaded files in Zend Framework

Jun 15, 2018 am 11:41 AM
framework zend upload files double naming

这篇文章主要介绍了Zend Framework上传文件重命名的实现方法,结合实例形式分析了Zend Framework上传文件重命名的具体操作步骤与配置、检测、重命名操作的相关实现技巧,需要的朋友可以参考下

本文实例讲述了Zend Framework上传文件重命名的实现方法。分享给大家供大家参考,具体如下:

1. Zend Framework文件上传重命名

//实例化文件上专类
$fName=$this->_request->getPost('fName');
$adapter = new Zend_File_Transfer_Adapter_Http();
//存放上传文件的文件夹
$adapter->setDestination('/opt/lampp/htdocs/blog/upload');
//上传配置
$adapter
->addValidator ( 'Extension', false, $configs['extension'])//文件格式限制
->addValidator('Size', false, array('min' =>floatval($configs['minsize']),
  'max' => floatval($configs['maxsize'])))//设置上传文件的大小在1-2M之间
->addValidator ( 'Count', false, array('min' => intval($configs['mincount']),
  'max' => intval($configs['maxcount'])) );//上传文件数量
//重命名配置
$fileInfo = $adapter->getFileInfo();//获取基本配置
$extName=$this->getExtension($fileInfo);//获取扩展名
$filename=md5(time()+$fileInfo['fFile']['name']).'.'.$extName;//重命名
$adapter->addFilter('Rename', array('target' => $filename, 'overwrite' => true));//执行重命名
//返回上传后出现在信息
if (!$adapter->receive())
{
  $messages = $adapter->getMessages ();//检测
  //Zend_Debug::dump($messages);
  $message='';
  if(is_array($messages))
  {
    foreach($messages as $k=>$v)
    {
      $message.=$k.&#39;:&#39;.$v.&#39;<br>&#39;;
    }
  }
  else
  {
    $message=$messages;
  }
}
else
{
  $this->view->message=&#39;上传成功!&#39;;
}
Copy after login

2. 获取文件扩展名

/**
 * 获取文件扩展名
 * @param String $name 文件名词
 * @author
 */
public function getExtension ($name)
{
  $fname=&#39;&#39;;
  if($name)
  {
    foreach ($name as $val)
    {
      $fname=$val[&#39;name&#39;];
    }
    $exts = @split("[/\\.]", $fname) ;
    $n = count($exts)-1;
    $exts = $exts[$n];
    return $exts;
  }
}
Copy after login

以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请关注PHP中文网!

相关推荐:

关于Zend Framework动作控制器的用法

Zend Framework中的Application和Bootstrap的用法

Zend Framework动作助手的用法解析

The above is the detailed content of About the implementation method of renaming uploaded files in Zend Framework. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1673
14
PHP Tutorial
1277
29
C# Tutorial
1257
24
The driver cannot load ene.sys on this device in Windows 11 The driver cannot load ene.sys on this device in Windows 11 May 05, 2023 am 09:13 AM

Many Windows 11 users have encountered the error message “The driver could not be loaded on this device (ene.sys)” which prevents the driver from loading on the system and is marked as vulnerable. However, this issue is mainly reported by users who have upgraded their PC to Windows 11. This error is closely related to drivers and files that get corrupted due to system operating system update issues. If you are encountering this “ene.sys” error every time you turn on your Windows 11 computer after an update, continue reading this article. Here you will find some troubleshooting methods that you can use if you see this error on your PC. Fix 1 – Install Optional Update Step 1. Use Windows+R group

4 Ways to Quickly Rename a Printer on Windows 11 4 Ways to Quickly Rename a Printer on Windows 11 Sep 11, 2023 pm 03:26 PM

If you have a lot of printers in your office, the printer list can be long and make getting work done tedious. What's more, multiple printers usually mean similar names, which can be a bit confusing. The last thing you want is to scroll through an endless list and still end up sending your print job to the wrong printer. Fortunately, you can solve all of these problems with a simple renaming trick, which we'll show you below. How do I rename my printer in Windows 11? 1. Using the Settings app tap the key and click Settings. Windows click Bluetooth and Devices and select Printers and Scanners. Select the printer you want to rename. Click Printer Properties. Navigate to the General tab, key

Microsoft NET Framework Installation Issues Error Code 0x800c0006 Fix Microsoft NET Framework Installation Issues Error Code 0x800c0006 Fix May 05, 2023 pm 04:01 PM

.NET Framework 4 is required by developers and end users to run the latest versions of applications on Windows. However, while downloading and installing .NET Framework 4, many users complained that the installer stopped midway, displaying the following error message - " .NET Framework 4 has not been installed because Download failed with error code 0x800c0006 ". If you are also experiencing it while installing .NETFramework4 on your device then you are at the right place

How to identify Windows upgrade issues using SetupDiag on Windows 11/10 How to identify Windows upgrade issues using SetupDiag on Windows 11/10 Apr 17, 2023 am 10:07 AM

Whenever your Windows 11 or Windows 10 PC has an upgrade or update issue, you will usually see an error code indicating the actual reason behind the failure. However, sometimes confusion can arise when an upgrade or update fails without an error code being displayed. With handy error codes, you know exactly where the problem is so you can try to fix it. But since no error code appears, it becomes challenging to identify the issue and resolve it. This will take up a lot of your time to simply find out the reason behind the error. In this case, you can try using a dedicated tool called SetupDiag provided by Microsoft that helps you easily identify the real reason behind the error.

How to upload files to 123 cloud disk How to upload files to 123 cloud disk Feb 24, 2024 pm 05:30 PM

How to upload files to 123 Cloud Disk? You can upload files to 123 Cloud Disk for storage, but most friends don’t know how to upload files to 123 Cloud Disk. Next is the picture and text of how to upload files to 123 Cloud Disk brought by the editor for players. Tutorial, interested users come and take a look! How to upload files on 123 Cloud Disk 1. First open 123 Cloud Disk and enter the main page, register or log in to the account; 2. Then enter the page as shown below, click the [Upload] button guided by the arrow; 3. Then the bottom will expand In the function bar window, click the [Select File] function; 4. Finally, select the file to be uploaded and wait patiently for the upload to complete.

Explorer.exe does not start on system startup [Fix] Explorer.exe does not start on system startup [Fix] Jun 03, 2023 am 08:31 AM

Nowadays, many Windows users start encountering severe Windows system problems. The problem is that Explorer.exe cannot start after the system is loaded, and users cannot open files or folders. Although, Windows users can open Windows Explorer manually using Command Prompt in some cases and this must be done every time the system restarts or after system startup. This can be problematic and is due to the following factors mentioned below. Corrupted system files. Enable fast startup settings. Outdated or problematic display drivers. Changes were made to some services in the system. Modified registry file. Keeping all the above factors in mind, we have come up with some that will surely help the users

How to batch rename file suffixes in win10 How to batch rename file suffixes in win10 Jul 06, 2023 pm 07:37 PM

How to batch rename file suffixes in win10? Nowadays, many users are using the Win10 system, and when we usually use computers, we often use a lot of shortcut keys, because shortcut keys can make our operations more convenient, so how do we rename files in batches? Below, the editor will introduce to you the operation of batch renaming files in Win10. How to batch rename files in Win10 1. Select all the files you want to rename. 2. Right-click on a selected file and select Rename. 3. After a file is renamed, other files will be marked with serial numbers in turn. The method is very simple, but when modifying, you need to pay attention to the order of the files and the sorting position of the modified sample files. The serial number starts from the modified sample file.

PHP function introduction—rename(): Rename a file or directory PHP function introduction—rename(): Rename a file or directory Jul 25, 2023 pm 12:10 PM

PHP function introduction—rename(): Renaming files or directories Introduction: In PHP, the rename() function is used to rename files or directories. It provides an easy way to change the name of a file or directory. Whether it is a single file or an entire directory, you can use this function to perform a rename operation. The renaming process can be easily accomplished by specifying the name of the source file or directory and the target name. Syntax: boolrename(string$source,str

See all articles