当前位置:网站首页>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 .
边栏推荐
- 将秒数转换为**小时**分钟
- Jerry's question about long press boot detection [chapter]
- Detailed steps for Django to upload excel tables and write data to the database
- Basic syntax of VB
- Jerry's touch key recognition process [chapter]
- 毕业季职场人
- 1045 error occurred in MySQL login. Modification method [easy to understand]
- 【Try to Hack】Windows系统账户安全
- CADD课程学习(2)-- 靶点晶体结构信息
- Kubevela 1.4: make application delivery safer, easier to use, and more transparent
猜你喜欢
![Jerry's touch key recognition process [chapter]](/img/a4/3affa0f03db158ab68f69f935945e0.png)
Jerry's touch key recognition process [chapter]

NLP skill tree learning route - (I) route overview

Primary school, session 3 - afternoon: Web_ sessionlfi

Spark - 一文搞懂 Partitioner

【论文阅读】Trajectory-guided Control Prediction for End-to-end Autonomous Driving: A Simple yet Strong Baseline

微信小程序开发实战 云音乐

NLP技能树学习路线-(一)路线总览

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

TorchDrug--药物属性预测

Audio and video architecture construction in the super video era | science and Intel jointly launched the second season of "architect growth plan"
随机推荐
Jenkins打包拉取不到最新的jar包
Halcon知识:盘点一下计量对象【1】
RP prototype resource sharing - shopping app
[try to hack] windows system account security
小学期,第三场-下午:WEB_sessionlfi
Web主机iptables防火墙安全脚本
DEX文件解析 - method_ids解析
Go 语言标识符、包名规范
杰理之触摸按键识别流程【篇】
GeoServer安装
Smarter! Airiot accelerates the upgrading of energy conservation and emission reduction in the coal industry
Heartbeat uses NFS to make MySQL highly available based on CRM
Introduction to neural network (Part 1)
QT qstringlist usage
毕业季职场人
TorchDrug--药物属性预测
VB的基本语法
昨晚 Spark Summit 重要功能发布全在这里(附超清视频)
Jerry's question about long press boot detection [chapter]
C语言:hashTable