一次Debug的遐想
ThinkPHP3.2 + PHP5.6 + Nginx1.8
Bug描述
上传文件提示 404,找不到文件。
Debug 过程
“我是上传文件,为啥会404?会不会是请求链接写错了?”
调试
操作:直接复制链接到浏览器访问。 结果 :状态码 200 ok 。
“链接没问题,难道是初始化工具类有问题?”
调试
操作:在工具类构造函数,打印数据并终止。 结果 :仍然404,跟工具类无关
“难道是框架自带Bug?”
调试
操作:新建项目,原生代码编写一个上传测试文件。 结果 :仍然404,跟框架无关
“既然跟程序无关,那就是服务器跟PHP问题了,是不是PHP有上传的控制参数默认关闭,然后我没有打开?没道理的,就算是,也不应该提示404,应该是服务器问题,可是直接访问链接是有效的,上传文件就404了,会不会是权限?最有可能就是这东西了,而且linux 下的权限控制非常严,上传文件要在某个目录先生成临时文件,然后通过复制函数,移动到指定目录才上传成功,如果程序对临时文件夹没有上传权限的话,报404是完全有可能的,问题是临时文件在哪儿呢?会上传到那个文件呢?”
调试
操作:google + baidu 结果 :都写的什么** 玩意,完全没有想要的内容。
“**,难道我要一个一个文件翻?对了,不是有日志?先看看服务器日志有没有信息“
调试
操作:打开nginx log 文件 结果 :清清楚楚的写着 /***/***/temp 目录,权限不足!
剩下的事情就很简单了, 一个修改权限语句完事。
总结 : 1.出现 bug时 ,一定要先想清楚问题会出现在哪个环节,接着就是查看运行的日志文件,一般都会有提示,如果看不懂什么意思,复制google 一下,一般都会找到问题的解决方案,除非你的bug已经达到深度无人涉及的程度。 2.对程序的了解程度,能有效的提高Debug的排错时间,如果换做一个菜鸟,估计写个原生上传都有难度,更不用说,看log,翻墙google了, 3.Debug 的速度能通过排错的经验,以及对程序的了解程序提升,正确的Debug方案能通过先人的教导获得。 4.多总结,多分享,主动学习往往比被动学习有效!

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

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio

In this article, we're going to explore the notification system in the Laravel web framework. The notification system in Laravel allows you to send notifications to users over different channels. Today, we'll discuss how you can send notifications ov
