php 文件服务器,GitHub - RainmanJin/PSFS: PHP Simple File Server 极简版PHP文件服务器
PSFS
PHP Simple File Server
This is a really simple solution to build a Central File Server for your site.
极简版的PHP文件服务器,可以应用于对文件服务性能和可用性要求不高的网站。
只有两个PHP文件,可以实现接收和保存POST过来的文件,并返回文件URL的功能。后续会继续进行扩展。
代码中的文件上传令牌是写死的,可以根据自己的需要进行访问合法性验证。
#Setup a place for your source code and Uploaded Files 创建PHP代码和文件保存目录
First, you need to setup a place to store the code and uploaded files.
mkdir ~/htdocs
cd htdocs
mkdir files
mkdir images
#Install Apache or Nginx as your web server 安装Nginx或Apache作为Web服务器
Open theweb server configuration file, edit or add location block, point to the code path.
location / {
root pathto/htdocs;
index index.php index.html index.htm;
}
Install PHP 安装PHP
#Test File Server 测试文件服务器
Open http://localhost/index.html, if you can see the form, the file server is up. 启动web服务器后,输入localhost/index.html,如果能够看到文件上传的Form表示服务已经启动。
Select a file and click submit, if you see a json string contains code and message, the file server should be running properly. 选择一个文件并点击提交,如果能够看到返回的包含返回码和消息的json字符串,文件服务器应该就正常运行了。
Java Code block to upload a file:
以下是实现文件上传的Java示例代码。 上传时以局域网的方式上传,返回则是可以直接在网站上引用的文件或图片的URL。
String fileServerInnerUrl = "http://192.168.10.3"; //LAN
String fileServerPublicUrl="http://xxx.xxx.com"; //WAN
String fileServerToken="asdfasdfadsfasdfwerqwer"; //token
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(fileServerInnerUrl + "file-upload.php");
MultipartEntityBuilder meb = MultipartEntityBuilder.create();
meb.addPart("file", new FileBody(file));
meb.addTextBody("token", fileServerToken);
HttpEntity reqEntity = meb.build();
httpPost.setEntity(reqEntity);
String strResult = null;
try {
CloseableHttpResponse response = httpClient.execute(httpPost);
if (response.getStatusLine().getStatusCode() == 200) {
strResult = EntityUtils.toString(response.getEntity(), "UTF-8");
JSONObject jsonObject = JSONObject.parseObject(strResult);
//If the code is "0", the file is uploaded, string message is the path.
String code = jsonObject.getString("code");
//If the code is not "0", file uploaded should be failed, then the message is error message.
String message = jsonObject.getString("message");
if("0".equals(code))
{
//fileURL is the url of uploaded file, can be used directly in your web page.
String fileURL = fileServerPublicUrl + message;
}
}
} catch (Exception e) {
e.printStackTrace();
}
php 文件服务器,GitHub - RainmanJin/PSFS: PHP Simple File Server 极简版PHP文件服务器相关推荐
- GitHub上如何进行PR(Pull Request)操作——简版
文章目录 一.实现步骤 1.将小红在GitHub上的Repository clone到小明的本地电脑 (1)fork小红在GitHub上的Repository到小明的GitHub (2)clone小明 ...
- 本地计算机架设http服务器,Http File Server(简易Http服务器服务端)
如果您感觉配置IIS和apache等web服务端太麻烦的话,不妨试试Http File Server,Http File Server是一套简易的Http服务器服务端系统,它无需安装,运行后简单配置一 ...
- http 文件服务器 性能测试,Http File Server
Http File Server测试版是一款http服务器软件.您可以使用Http File Server进行发送和接收文件,运行速度快,操作简单.Http File Server支持下载和上传.虚拟 ...
- 2022 *CTF REVERSE的Simple File System
2022 *CTF REVERSE的Simple File System . . 下载附件,有四个文件: . . 照例扔入虚拟机中运行一下,查看主要回显信息: . . 照例扔入 IDA64 中查看伪代 ...
- 在PC上File Server (FTP)文件服务器搭建
一.搭建环境 1.笔记本电脑 2.操作系统:Win7 X64 二.搭建步骤 1.安装IIS,安装步骤如下: (1).打开"控制面板"--->"程序" (2 ...
- 文件服务器策略,的Adobe套接字策略文件服务器问题(Adobe Socket Policy File Server
任何人都已经能够成功地实现服务,服务需要套接字策略文件,flash播放? 我正在由Adobe在提供的服务的Python实现 http://www.adobe.com/devnet/flashplaye ...
- linux未设置为接受端口,Simple gawk server
# 指定对话框左上角在屏幕的上的做坐标 --timeout # 超时,返回的错误代码255,如果用户在指定的时间内没有给出相应动作,就按超时处理 --defaultno # 使选择默认为no --de ...
- srs ~ Simple Realtime Server ~ 流媒体解决方案。
srs ~ Simple Realtime Server ~ 流媒体解决方案. 文章目录 srs ~ Simple Realtime Server ~ 流媒体解决方案. 推流协议. RTMP. HTT ...
- Simple Web Server
web服务器hello world!-----简单的socket通信实现. HTTP HTTP是Web浏览器与Web服务器之间通信的标准协议,HTTP指明了客户端如何与服务器建立连接,如果从服务器请求 ...
- netatalk,轻松将linux变成你的Mac File Server!!!
为什么80%的码农都做不了架构师?>>> netatalk (http://netatalk.sourceforge.net),轻松将linux变成你的Mac File Ser ...
最新文章
- canva五角星空html,【Canvas】canva实例-星空、日出的效果
- linux内核杂记(9)-进程调度(4)
- matlab能做深度图像的识别吗,Matlab图像识别/检索系列(6)-10行代码完成深度学习网络之基于CNN的图像分类...
- 如何在64位Ubuntu16.04下安装java开发环境
- UCGUI的模拟器UCGUISim详解
- [react] react中你用过哪些第三方的中间件
- 【渝粤教育】国家开放大学2018年秋季 0077-22T古代汉语专题 参考试题
- php有c语言基础教程,c语言必背入门代码
- Java链表——插入和删除
- 设置google浏览器为黑色底色
- 阿里云Landing Zone系列--1云治理中心使用
- 小游戏《塔防》开发(一)上篇
- C++安装失败解决办法
- EBU5502 Database Coursework Specifications
- WS2812C IO口模拟控制
- 使用cookie实现一周内自动登录
- 如何用usb电缆连接到计算机,如何使用USB串行电缆将文件从计算机传输到树莓派...
- java implement和extends
- 南京印象之出租车司机
- 编程小伙不想做核酸,竟伪造绿码,警察蜀黍送上 5 日行拘套餐!