表示没有下载

时间:2015-07-07 23:46:00

标签: php

我计划在服务器上查询php文件,如下所示:

example.com/download.php?value=7

如果此值符合特定条件,则服务器应使用实际内容进行响应。如果该值未通过此条件,我希望服务器以某种类型的“null”值进行响应。最好的做法是创建一个空的临时文件并将其返回,还是有更“标准”的方式来回复没有什么可下载的?

2 个答案:

答案 0 :(得分:1)

在这种情况下,最佳响应是让服务器返回404错误。来自规范:

The server has not found anything matching the Request-URI. No indication is given of whether the condition is temporary or permanent. The 410 (Gone) status code SHOULD be used if the server knows, through some internally configurable mechanism, that an old resource is permanently unavailable and has no forwarding address. This status code is commonly used when the server does not wish to reveal exactly why the request has been refused, or when no other response is applicable. 

最好的方法可以在How can I create an error 404 in PHP?

找到

答案 1 :(得分:1)

在这种情况下,最佳做法是返回meaningful HTTP response code。如果请求是针对丢失的文件或资源,则可以选择404 NOT FOUND,如果请求的格式不正确,则可以选择400 BAD REQUEST。查看this tutorial以获取有关PHP的更多RESTful最佳实践。