php上传功能集后缀名判断和随机命名,php上传后缀命名
php上传功能集后缀名判断和随机命名,php上传后缀命名
form.php
<span><</span><span>html</span><span>></span> <span><</span><span>head</span><span>></span> <span><</span><span>meta </span><span>http-equiv</span><span>="content-type"</span><span> content</span><span>="text/html"</span><span> charset</span><span>="utf-8"</span><span>></span> <span><</span><span>title</span><span>></span>Upload Image<span></</span><span>title</span><span>></span> <span></</span><span>head</span><span>></span> <span><</span><span>body</span><span>></span> <span><</span><span>form </span><span>method</span><span>="post"</span><span> action</span><span>="upload.php"</span><span> enctype</span><span>="multipart/form-data"</span><span>></span> <span><</span><span>input </span><span>type</span><span>="hidden"</span><span> name</span><span>="MAX_FILE_SEZE"</span><span> value</span><span>="2000000"</span><span>></span> <span><</span><span>input </span><span>type</span><span>="file"</span><span> name</span><span>="file"</span><span> value</span><span>="view"</span><span>></span> <span><</span><span>input </span><span>type</span><span>="submit"</span><span> value</span><span>="upload"</span><span> name</span><span>="B1"</span><span>></span> <span></</span><span>form</span><span>></span> <span></</span><span>body</span><span>></span> <span></</span><span>html</span><span>></span>
upload.php
<?<span>php </span><span>include</span>("check.php"); <span>//</span><span> 引入自定义函数文件</span> <span>$type</span> = <span>array</span>("jpg", "gif", "bmp", "jpeg", "png"<span>); </span><span>//</span><span> 判断上传文件类型</span> <span>$fileext</span> = <span>strtolower</span>(fileext(<span>$_FILES</span>['file']['name'<span>])); </span><span>$uploadfilename</span> = random(8<span>); </span><span>if</span>(<span>in_array</span>(<span>$fileext</span>, <span>$type</span><span>)){ </span><span>$filename</span> = <span>explode</span>(".", <span>$_FILES</span>['file']['name'<span>]); </span><span>if</span>(<span>is_uploaded_file</span>(<span>$_FILES</span>['file']['tmp_name'<span>])){ </span><span>//</span><span> echo $_FILES['file']['tmp_name'];</span> <span>$flag</span> = <span>move_uploaded_file</span>(<span>$_FILES</span>['file']['tmp_name'], "/Library/WebServer/Documents/test/".<span>$uploadfilename</span>.".".<span>$fileext</span><span>); </span><span>if</span>(<span>$flag</span><span>){ </span><span>echo</span> "上传成功!"<span>; }</span><span>else</span><span>{ </span><span>echo</span> "Error."<span>; } </span><span>echo</span> "<a href='javascript:history.go(-1)'>Back</a>"<span>; } }</span>
check.php
<?<span>php </span><span>header</span>("Content-type:text/html;charset=utf8"<span>); </span><span>//</span><span> 获取文件后缀名函数</span> <span>function</span> fileext(<span>$filename</span><span>){ </span><span>$sTemp</span> = <span>strrchr</span>(<span>$filename</span>, "."<span>); </span><span>return</span> <span>substr</span>(<span>$sTemp</span>, 1<span>); } </span><span>function</span> fileext2(<span>$filename</span><span>){ </span><span>$sTemp</span> = <span>explode</span>(".", <span>$filename</span><span>); </span><span>return</span> <span>$sTemp</span>[<span>count</span>(<span>$sTemp</span>)-1<span>]; } </span><span>//</span><span> 生成随机文件名函数</span> <span>function</span> random(<span>$length</span><span>){ </span><span>$captchaSource</span> = "0123456789abcdefghijklmnopqrstuvwxyz这是一个随机打印输出字符串的例子"<span>; </span><span>$captchaResult</span> = "2015"; <span>//</span><span> 随机数返回值</span> <span>$captchaSentry</span> = ""; <span>//</span><span> 随机数中间变量</span> <span>for</span>(<span>$i</span>=0;<span>$i</span><<span>$length</span>;<span>$i</span>++<span>){ </span><span>$n</span> = <span>rand</span>(0, 35); <span>#</span><span>strlen($captchaSource));</span> <span>if</span>(<span>$n</span> >= 36<span>){ </span><span>$n</span> = 36 + <span>ceil</span>((<span>$n</span>-36)/3) * 3<span>; </span><span>$captchaResult</span> .= <span>substr</span>(<span>$captchaSource</span>, <span>$n</span>, 3<span>); }</span><span>else</span><span>{ </span><span>$captchaResult</span> .= <span>substr</span>(<span>$captchaSource</span>, <span>$n</span>, 1<span>); } } </span><span>return</span> <span>$captchaResult</span><span>; } </span>?>
将三个文件整合成一个:
<?<span>php </span><span>//</span><span> 获取文件后缀名函数</span> <span>function</span> fileext(<span>$filename</span><span>){ </span><span>$sTemp</span> = <span>strrchr</span>(<span>$filename</span>, "."<span>); </span><span>return</span> <span>substr</span>(<span>$sTemp</span>, 1<span>); } </span><span>function</span> fileext2(<span>$filename</span><span>){ </span><span>$sTemp</span> = <span>explode</span>(".", <span>$filename</span><span>); </span><span>return</span> <span>$sTemp</span>[<span>count</span>(<span>$sTemp</span>)-1<span>]; } </span><span>//</span><span> 生成随机文件名函数</span> <span>function</span> random(<span>$length</span><span>){ </span><span>$captchaSource</span> = "0123456789abcdefghijklmnopqrstuvwxyz这是一个随机打印输出字符串的例子"<span>; </span><span>$captchaResult</span> = "2015"; <span>//</span><span> 随机数返回值</span> <span>$captchaSentry</span> = ""; <span>//</span><span> 随机数中间变量</span> <span>for</span>(<span>$i</span>=0;<span>$i</span><<span>$length</span>;<span>$i</span>++<span>){ </span><span>$n</span> = <span>rand</span>(0, 35); <span>#</span><span>strlen($captchaSource));</span> <span>if</span>(<span>$n</span> >= 36<span>){ </span><span>$n</span> = 36 + <span>ceil</span>((<span>$n</span>-36)/3) * 3<span>; </span><span>$captchaResult</span> .= <span>substr</span>(<span>$captchaSource</span>, <span>$n</span>, 3<span>); }</span><span>else</span><span>{ </span><span>$captchaResult</span> .= <span>substr</span>(<span>$captchaSource</span>, <span>$n</span>, 1<span>); } } </span><span>return</span> <span>$captchaResult</span><span>; } </span><span>$type</span> = <span>array</span>("jpg", "gif", "bmp", "jpeg", "png"<span>); </span><span>//</span><span> 判断上传文件类型</span> <span>$fileext</span> = <span>strtolower</span>(fileext(<span>$_FILES</span>['file']['name'<span>])); </span><span>$uploadfilename</span> = random(8<span>); </span><span>if</span>(<span>in_array</span>(<span>$fileext</span>, <span>$type</span><span>)){ </span><span>$filename</span> = <span>explode</span>(".", <span>$_FILES</span>['file']['name'<span>]); </span><span>if</span>(<span>is_uploaded_file</span>(<span>$_FILES</span>['file']['tmp_name'<span>])){ </span><span>//</span><span> echo $_FILES['file']['tmp_name'];</span> <span>$flag</span> = <span>move_uploaded_file</span>(<span>$_FILES</span>['file']['tmp_name'], "/Library/WebServer/Documents/test/".<span>$uploadfilename</span>.".".<span>$fileext</span><span>); </span><span>if</span>(<span>$flag</span><span>){ </span><span>echo</span> "上传成功!"<span>; }</span><span>else</span><span>{ </span><span>echo</span> "Error."<span>; } </span><span>echo</span> "<a href='javascript:history.go(-1)'>Back</a>"<span>; } } </span>?> <html> <head> <meta http-equiv="content-type" content="text/html" charset="utf-8"> <title>Upload Image</title> </head> <body> <form method="post" action="" enctype="multipart/form-data"> <input type="hidden" name="MAX_FILE_SEZE" value="2000000"> <input type="file" name="file" value="view"> <input type="submit" value="upload" name="B1"> </form> </body> </html>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



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

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
![Explorer.exe does not start on system startup [Fix]](https://img.php.cn/upload/article/000/887/227/168575230155539.png?x-oss-process=image/resize,m_fill,h_207,w_330)
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? 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.

Just like any other game on your PC, Counter-Strike: Global Offensive can crash, freeze, or get stuck in a black screen on launch. Counter-Strike is one of the low resource fps games on the market and it even runs on Tudou PC. Although CSGO is a CPU-oriented game, the system GPU also plays an important role. The black screen issue is related to GPU issues. Follow these simple solutions to solve the problem. Fix 1 – Turn off compatibility If you are running the game in compatibility mode on Windows 8 or 7, turn it off. CSGO works with every version of Windows (WindowsXP or higher)

The shortcut key for renaming is F2. Analysis 1 The shortcut key for renaming is F2. 2 If you want to rename a file or folder, you can press F2 after selecting the file, modify it directly and press Enter. 3 Sometimes you can also use the mouse to select the file, right-click, select Rename, and press Enter after the modification is completed. 4 Shortcut keys refer to the special combination or sequence of keys on the keyboard to quickly complete a certain command, which can effectively improve work efficiency. Supplement: What are shortcut keys? 1 Shortcut keys, also called hot keys, refer to completing an operation through certain specific keys, key sequences or key combinations. You can use shortcut keys to do some work instead of the mouse. You can use keyboard shortcuts to open, close, and navigate the start menu, desktop, menus, and dialog boxes.

Changing the file type (extension) is a simple task. However, sometimes simpler things can get tricky, and changing file extensions is one of them. Extreme care should be taken when changing file types, as a simple mistake can brick the file and render it inoperable. So, we discussed various ways to change file types on Windows 11, 10. How to Change File Type on Windows 11, 10 There are two ways to do this. You can use the direct GUI method (in File Explorer) or you can change the file type from the terminal. Way 1 – Using File Explorer Way 2 – Using CMD Terminal Way 1 – Changing the file type directly You can directly change the file type from up and down in File Explorer

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
