php资料的上传与删除方法
php文件的上传与删除方法
1.php文件的上传
先简单布局一个html操作界面:(图片上传为例)
submit提交之后,然后判断上传的文件是否为空。同时可以进行文件大小的控制,获取文件名之后,上传文件。
<?php if($_POST["submit"]) { //通过字符串截取函数explode()截取出文件后缀名 $name = $_FILES['photo']['name']; <span style="font-family: Arial, Helvetica, sans-serif;">//获取上传文件的文件名 $string = explode(".",$name); $i = count($string); $substring = $string[$i-1]; //判断文件大小,名称 if($_FILES['photo']['size'] > 0 && $_FILES['photo']['name']) { $dir = 'upfiles/'; //设置保存目录 if(!is_dir($dir)) //如果没有该目录 { mkdir($dir); //则创建该目录 } $format = "Yndhis"; $date = date($format); //可以通过设置当前时间来重命名文件名 $name = $date.".".$substring; //重新组合文件名 当前时间.文件后缀名 $path = 'upfiles/'.$name; //组合成完整的保存路径(目录+文件名) $i = move_uploaded_file($_FILES['photo']['tmp_name'],$path); //保存文件到创建的目录下 if($i == false) { echo "<script>alert('文件保存失败!');</script>"; //echo $path; } //保存到数据库中,保存链接信息(文件地址)到数据库中,即例中的p_url $str = "INSERT INTO picture(s_id,p_url,p_info)VALUES($sid,'$path','$info')"; $result = mysql_query($str); if($result) { echo "<script>alert('图片添加成功!');</script>"; } else { //echo $str; echo "<script>alert('图片添加失败!');</script>"; } } } ?>
文件上传的主要php函数就是move_upload_file("文件名","文件路径"),注意不要写错了。
2.php文件删除
php文件删除只需要使用unlink()函数即可。
<?php /* 图片删除处理页 */ if($_GET["p_url"]) { $purl = $_GET["p_url"]; //获取文件保存路径 $file_delete = "../".$purl; //根据自己的文件目录设置路径信息 $str = "DELETE FROM picture WHERE p_url='".$purl."'"; //从数据库中删除图片文件 $delete = mysql_query($str); if($delete) { unlink($file_delete); //从自己写入的路径删除图片文件 echo "<script>alert('图片信息删除成功!');window.location.href='picture_manage.php'"; } else { //echo $str; echo "<script>alert('图片信息删除失败!');window.location.href='picture_manage.php'</script>"; } } else { echo "<script>alert('请选择要删除的图片信息!');window.location.href='picture_manage.php'</script>"; } ?>

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 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

Script means script or script. In film, television, drama and other art forms, script is used to describe the dialogue, actions and scenes of characters, as well as the development and structure of the story. Script writing requires certain skills and experience, and it should be vivid and powerful, capable of attracting the audience's attention and conveying the emotions and themes of the story. Scripts are particularly important in the film and television industries. They are the basis of creation and determine the storyline, character development and dialogue content of the film. Script is an important tool for artists to create and express themselves.

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

In the field of computer science, "script" usually refers to a scripting language or script file. A scripting language is an interpreted programming language commonly used for tasks such as automation, batch processing, and rapid prototyping.

Watch4pro and gt each have different features and applicable scenarios. If you focus on comprehensive functions, high performance and stylish appearance, and are willing to bear a higher price, then Watch 4 Pro may be more suitable. If you don’t have high functional requirements and pay more attention to battery life and reasonable price, then the GT series may be more suitable. The final choice should be decided based on personal needs, budget and preferences. It is recommended to carefully consider your own needs before purchasing and refer to the reviews and comparisons of various products to make a more informed choice.

Solutions to scripterror include checking syntax, file path, checking network connection, browser compatibility, using try-catch statements, using developer tools for debugging, updating browsers and JavaScript libraries, or seeking professional help. Detailed introduction: 1. Check for syntax errors: Script Error may be caused by syntax errors in JavaScript code. Use developer tools to check the code and fix syntax errors. Make sure that the brackets, quotation marks, semicolons, etc. in the code are correct. etc.
