php upload file
upLoad.php
<html> <head> <!-- <link rel="stylesheet" href="myCss.css" type="text/css" /> --> </head> <div class="register"> <form enctype="multipart/form-data" method="post" action="upLoadProcess.php" name="myform"> <table> <tr> <td align="center" colspan="2"><font style="font-size:40px;font-family:华文彩云">文件上传</font></td> </tr> <tr> <td>请填写用户名:</td> <td><input type="text" name="username"/></td> </tr> <tr> <td>请简单介绍该文件</td> <td><TEXTAREA name="fileintro" rows="10" cols="80"></TEXTAREA></td> </tr> <tr> <td colspan="2">请选择要上传的文件:<input type="file" name="myfile"/></td> </tr> <tr> <td align="center" colspan="2"><input type="submit" value="上传文件" /></td> </tr> </table> </form> </div> </html> <?php if(isset($_GET['flag'])){ $flag = $_GET['flag']; if($flag == 1){ echo "<br/<br/><font style='color:red'>文件大小不能超过2M</font>"; } } ?>
upLoadProcess.php
<?php //接收提交文件的信息 if(isset($_POST['username'])){ $username=$_POST['username']; }else{ echo "上传文件失败"; exit(); } if(isset($_POST['fileintro'])){ $fileintro = $_POST['fileintro']; } $file_size = $_FILES['myfile']['size']; if($file_size > 2*1024*1024){ echo "<font style='color:red'>文件过大,不能上传超过2M的文件</font><br/>"; echo "<a href='upLoad.php'>返回重新上传</a>"; exit(); } $file_type = $_FILES['myfile']['type']; if($file_type != "image/jpg" && $file_type != "image/pjpeg"){ echo "文件类型只能是jpg的"; exit(); } // echo "<pre class="brush:php;toolbar:false">"; // print_r($_FILES); // echo ""; if(is_uploaded_file($_FILES['myfile']['tmp_name'])){ //把文件转存到你希望的目录; $upLoaded_file = $_FILES['myfile']['tmp_name']; $fileName = $_FILES['myfile']['name']; //给每个用户动态的创建一个文件夹 $user_path = $_SERVER['DOCUMENT_ROOT']."/fileOpt/upLoadFiles/".$username; if(!file_exists($user_path)){ mkdir($user_path); } //$destPath = $user_path."/".$fileName; $destPath = $user_path."/".(time().rand(0,1000)).substr($fileName,strrpos($fileName, ".")); //如果目标文件存在,则被覆盖 if(move_uploaded_file($upLoaded_file,$destPath)){ echo $_FILES['myfile']['name']." 上传成功!"; }else{ echo "上传失败!
"; echo "返回重新上传"; } }else{ echo "上传失败!
"; echo "返回重新上传"; } ?>
The above introduces PHP file uploading, including aspects of content. I hope it will be helpful to friends who are interested in PHP tutorials.

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

AI Hentai Generator
Generate AI Hentai for free.

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 users will choose the Huawei brand when choosing smart watches. Among them, Huawei GT3pro and GT4 are very popular choices. Many users are curious about the difference between Huawei GT3pro and GT4. Let’s introduce the two to you. . What are the differences between Huawei GT3pro and GT4? 1. Appearance GT4: 46mm and 41mm, the material is glass mirror + stainless steel body + high-resolution fiber back shell. GT3pro: 46.6mm and 42.9mm, the material is sapphire glass + titanium body/ceramic body + ceramic back shell 2. Healthy GT4: Using the latest Huawei Truseen5.5+ algorithm, the results will be more accurate. GT3pro: Added ECG electrocardiogram and blood vessel and safety

Why Snipping Tool Not Working on Windows 11 Understanding the root cause of the problem can help find the right solution. Here are the top reasons why the Snipping Tool might not be working properly: Focus Assistant is On: This prevents the Snipping Tool from opening. Corrupted application: If the snipping tool crashes on launch, it might be corrupted. Outdated graphics drivers: Incompatible drivers may interfere with the snipping tool. Interference from other applications: Other running applications may conflict with the Snipping Tool. Certificate has expired: An error during the upgrade process may cause this issu simple solution. These are suitable for most users and do not require any special technical knowledge. 1. Update Windows and Microsoft Store apps

In today's era of rapid technological development, programming languages are springing up like mushrooms after a rain. One of the languages that has attracted much attention is the Go language, which is loved by many developers for its simplicity, efficiency, concurrency safety and other features. The Go language is known for its strong ecosystem with many excellent open source projects. This article will introduce five selected Go language open source projects and lead readers to explore the world of Go language open source projects. KubernetesKubernetes is an open source container orchestration engine for automated

"Go Language Development Essentials: 5 Popular Framework Recommendations" As a fast and efficient programming language, Go language is favored by more and more developers. In order to improve development efficiency and optimize code structure, many developers choose to use frameworks to quickly build applications. In the world of Go language, there are many excellent frameworks to choose from. This article will introduce 5 popular Go language frameworks and provide specific code examples to help readers better understand and use these frameworks. 1.GinGin is a lightweight web framework with fast

Part 1: Initial Troubleshooting Steps Checking Apple’s System Status: Before delving into complex solutions, let’s start with the basics. The problem may not lie with your device; Apple's servers may be down. Visit Apple's System Status page to see if the AppStore is working properly. If there's a problem, all you can do is wait for Apple to fix it. Check your internet connection: Make sure you have a stable internet connection as the "Unable to connect to AppStore" issue can sometimes be attributed to a poor connection. Try switching between Wi-Fi and mobile data or resetting network settings (General > Reset > Reset Network Settings > Settings). Update your iOS version:

php提交表单通过后,弹出的对话框怎样在当前页弹出php提交表单通过后,弹出的对话框怎样在当前页弹出而不是在空白页弹出?想实现这样的效果:而不是空白页弹出:------解决方案--------------------如果你的验证用PHP在后端,那么就用Ajax;仅供参考:HTML code

Laravel is a popular PHP framework that is highly scalable and efficient. It provides many powerful tools and libraries that allow developers to quickly build high-quality web applications. Among them, LaravelEcho and Pusher are two very important tools through which WebSockets communication can be easily implemented. This article will detail how to use these two tools in Laravel applications. What are WebSockets? WebSockets

With the development of the Internet and the advancement of information technology, the era of big data has arrived, and fields such as data analysis and machine learning have also been widely used. In these fields, task scheduling is an inevitable problem. How to achieve efficient task scheduling is crucial to improving efficiency. In this article, we will introduce how to use Golang's web framework Echo framework to implement distributed task scheduling. 1. Introduction to the Echo framework Echo is a high-performance, scalable, lightweight GoWeb framework. It is based on HTTP
