当前位置:网站首页>Summary of PHP file upload (garbled code, move failure, permission, display picture)
Summary of PHP file upload (garbled code, move failure, permission, display picture)
2022-06-30 20:18:00 【Brother Xing plays with the clouds】
LAMP Environmental Science :
Linux Mint 16 32bits xfce
apache 2.4.6 Ubuntu
php 5.5.3
Default www yes /var/www, I used symbols to connect to /home/tony/www
And then modify sudo chmod 777 www
Upload page code :
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <body>
<form action="upload_file.php" method="post" enctype="multipart/form-data"> <label for="file">Filename:</label> <input type="file" name="file" id="file" /> <br /> <input type="submit" name="submit" value="Submit" /> </form>
</body> </html>
This code needs to add head Indicates the character set , The following code is the same
<head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <?php if ($_FILES["file"]["error"] > 0) { echo "Error: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " .$_FILES["file"]["name"]. "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Stored in: " . $_FILES["file"]["tmp_name"]."<br />"; } if(is_uploaded_file($_FILES["file"]["tmp_name"])){ echo "legal uploaded file<br>"; }else echo "illegai uploaded file<br>"; $src_path= $_FILES["file"]["tmp_name"]; $des_path= '/home/tony/www/upload/'."a.jpg"; //$des_path= '/home/tony/www/upload/'.$_FILES["file"]["name"]; echo $src_path . "<br />"; echo $des_path . "<br />"; if(file_exists($src_path)){ echo "file exists.<br />"; } if(move_uploaded_file($src_path,$des_path)){ echo "Stored in: "."<br />"; }else echo"<br>move failed."; printf("<img src=%s />","upload/a.jpg"); ?>
This piece of code is miscellaneous , Not beautiful . But it illustrates some problems .
1/ Still specify the character set , Otherwise, there will be problems on different browsers or systems ,apache2 The configuration file of does not AddDefaultCharset function , If it has been changed, please change it to AddDefaultCharset Off; restart apache2
2/ Temporary files in php It will disappear after execution , Hard to see with the naked eye , You can have one at the end while(1);
3/ Someone asked why you can't use other functions to transfer uploaded files ? Now that I have a path .http This upload mechanism can ensure a certain degree of security , If you can verify the security of the upload , Other functions are also competent
4/ I always move You don't succeed , After several investigations , The new path does not have permission , All are linux The safety of . Try to use chmod -R 777 www, Find the bottom upload Not obtained 777 Authority ... This is a bug? Back to the upload Just change the permission
Finally, the absolute path cannot be used to insert the picture , Use a relative path , So far I don't understand why
It should be handled during uploading php Add some file type detection there , File header detection , Restriction of forbidden operation , I'll fill in these security or function restrictions when I'm free .
边栏推荐
- QT qstringlist usage
- C language: hashtable
- 8 - 函数
- 太湖 “中国健康农产品·手机直播万里行”走进太湖
- QT :QAxObject操作Excel
- QT QStringList用法
- 屏幕显示技术进化史
- Perl转换文件的编码类型
- 25: Chapter 3: developing pass service: 8: [registration / login] interface: receiving and verifying "mobile number and verification code" parameters; (it is important to know the application scenario
- Jenkins can't pull the latest jar package
猜你喜欢

消灭Bug,开发者不可不知的几款Bug探索测试神器。

Spark - 一文搞懂 Partitioner

杰理之触摸按键识别流程【篇】

小学期,第三场-下午:WEB_xxe

昨晚 Spark Summit 重要功能发布全在这里(附超清视频)

Detailed explanation of specific methods and steps for TCP communication between s7-1500 PLCs (picture and text)

Data intelligence - dtcc2022! China database technology conference is about to open

CADD课程学习(2)-- 靶点晶体结构信息

CV+Deep Learning——网络架构Pytorch复现系列——basenets(BackBones)(一)

Why must a digital transformation strategy include continuous testing?
随机推荐
Tensorflow2.4 implementation of repvgg
Solution to rollback of MySQL database by mistake deletion
Heartbeat 与DRBD 配置过程
DEX文件解析 - method_ids解析
Django上传excel表格并将数据写入数据库的详细步骤
MySQL数据库误删回滚的解决
线下门店为什么要做新零售?
4.3-inch touch screen 12 channel control port programmable network central control supports mutual backup of 5 central control hosts
如何快速通过PMP考试?
杰理之关于长按开机检测抬起问题【篇】
NLP技能树学习路线-(一)路线总览
CADD course learning (1) -- basic knowledge of drug design
S7-1500 PLC之间进行TCP通信的具体方法和步骤详解(图文)
Source code analysis of redis ziplist compressed list
建立自己的网站(20)
Why must we move from Devops to bizdevops?
TorchDrug--药物属性预测
Filebeat custom indexes and fields
C language: hashtable
【1175. 质数排列】