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文件服务器相关推荐

  1. GitHub上如何进行PR(Pull Request)操作——简版

    文章目录 一.实现步骤 1.将小红在GitHub上的Repository clone到小明的本地电脑 (1)fork小红在GitHub上的Repository到小明的GitHub (2)clone小明 ...

  2. 本地计算机架设http服务器,Http File Server(简易Http服务器服务端)

    如果您感觉配置IIS和apache等web服务端太麻烦的话,不妨试试Http File Server,Http File Server是一套简易的Http服务器服务端系统,它无需安装,运行后简单配置一 ...

  3. http 文件服务器 性能测试,Http File Server

    Http File Server测试版是一款http服务器软件.您可以使用Http File Server进行发送和接收文件,运行速度快,操作简单.Http File Server支持下载和上传.虚拟 ...

  4. 2022 *CTF REVERSE的Simple File System

    2022 *CTF REVERSE的Simple File System . . 下载附件,有四个文件: . . 照例扔入虚拟机中运行一下,查看主要回显信息: . . 照例扔入 IDA64 中查看伪代 ...

  5. 在PC上File Server (FTP)文件服务器搭建

    一.搭建环境 1.笔记本电脑 2.操作系统:Win7 X64 二.搭建步骤 1.安装IIS,安装步骤如下: (1).打开"控制面板"--->"程序" (2 ...

  6. 文件服务器策略,的Adobe套接字策略文件服务器问题(Adobe Socket Policy File Server

    任何人都已经能够成功地实现服务,服务需要套接字策略文件,flash播放? 我正在由Adobe在提供的服务的Python实现 http://www.adobe.com/devnet/flashplaye ...

  7. linux未设置为接受端口,Simple gawk server

    # 指定对话框左上角在屏幕的上的做坐标 --timeout # 超时,返回的错误代码255,如果用户在指定的时间内没有给出相应动作,就按超时处理 --defaultno # 使选择默认为no --de ...

  8. srs ~ Simple Realtime Server ~ 流媒体解决方案。

    srs ~ Simple Realtime Server ~ 流媒体解决方案. 文章目录 srs ~ Simple Realtime Server ~ 流媒体解决方案. 推流协议. RTMP. HTT ...

  9. Simple Web Server

    web服务器hello world!-----简单的socket通信实现. HTTP HTTP是Web浏览器与Web服务器之间通信的标准协议,HTTP指明了客户端如何与服务器建立连接,如果从服务器请求 ...

  10. netatalk,轻松将linux变成你的Mac File Server!!!

    为什么80%的码农都做不了架构师?>>>    netatalk (http://netatalk.sourceforge.net),轻松将linux变成你的Mac File Ser ...

最新文章

  1. canva五角星空html,【Canvas】canva实例-星空、日出的效果
  2. linux内核杂记(9)-进程调度(4)
  3. matlab能做深度图像的识别吗,Matlab图像识别/检索系列(6)-10行代码完成深度学习网络之基于CNN的图像分类...
  4. 如何在64位Ubuntu16.04下安装java开发环境
  5. UCGUI的模拟器UCGUISim详解
  6. [react] react中你用过哪些第三方的中间件
  7. 【渝粤教育】国家开放大学2018年秋季 0077-22T古代汉语专题 参考试题
  8. php有c语言基础教程,c语言必背入门代码
  9. Java链表——插入和删除
  10. 设置google浏览器为黑色底色
  11. 阿里云Landing Zone系列--1云治理中心使用
  12. 小游戏《塔防》开发(一)上篇
  13. C++安装失败解决办法
  14. EBU5502 Database Coursework Specifications
  15. WS2812C IO口模拟控制
  16. 使用cookie实现一周内自动登录
  17. 如何用usb电缆连接到计算机,如何使用USB串行电缆将文件从计算机传输到树莓派...
  18. java implement和extends
  19. 南京印象之出租车司机
  20. 编程小伙不想做核酸,竟伪造绿码,警察蜀黍送上 5 日行拘套餐!

热门文章

  1. 2月12 CNN结构特征+Faster R-CNN
  2. 10 种最流行的 Web 挖掘工具
  3. Introduction to Conditional Random Fields
  4. 数据--第23课 - 队列的优化实现
  5. moss form验证 配置文件关键部分
  6. 凸优化第四章凸优化问题 4.1 优化问题
  7. 项目中关于IFRAME引发的问题【出现率很高】
  8. Android驱动工程师职位要求
  9. Linux Ubuntu从零开始部署web环境及项目 -----部署项目 (三)
  10. 消息中间件activemq-5.13.0安全验证配置