example: migrate php-xhr to ESM (#4009)

This commit is contained in:
Antoine du Hamel 2022-08-19 10:56:38 +02:00 committed by GitHub
parent 8ac6091e1a
commit 655b8ba61b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 32 additions and 40 deletions

View file

@ -195,8 +195,9 @@ module.exports = {
'examples/aws-presigned-url/*.js',
'examples/bundled/*.js',
'examples/custom-provider/client/*.js',
'examples/node-xhr/*.js',
'examples/multiple-instances/*.js',
'examples/node-xhr/*.js',
'examples/php-xhr/*.js',
'examples/transloadit-markdown-bin/*.js',
'examples/xhr-bundle/*.js',
'private/dev/*.js',

View file

@ -1,2 +1 @@
uppy.min.css
uploads
uploads/

View file

@ -6,15 +6,15 @@ This example uses PHP server and `@uppy/xhr-upload` to upload files to the local
To run this example, make sure you've correctly installed the **repository root**:
```bash
npm install
npm run build
```sh
corepack yarn install
corepack yarn build
```
That will also install the dependencies for this example.
Then, again in the **repository root**, start this example by doing:
```bash
npm run example php-xhr
```sh
corepack yarn workspace @uppy-example/php-xhr start
```

View file

@ -4,9 +4,8 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>PHP + Uppy Example</title>
<link href="uppy.min.css" rel="stylesheet">
</head>
<body>
<script src="bundle.js"></script>
<script src="./main.js" type="module"></script>
</body>
</html>

View file

@ -1,7 +1,11 @@
const Uppy = require('@uppy/core')
const Webcam = require('@uppy/webcam')
const Dashboard = require('@uppy/dashboard')
const XHRUpload = require('@uppy/xhr-upload')
import Uppy from '@uppy/core'
import Webcam from '@uppy/webcam'
import Dashboard from '@uppy/dashboard'
import XHRUpload from '@uppy/xhr-upload'
import '@uppy/core/dist/style.css'
import '@uppy/dashboard/dist/style.css'
import '@uppy/webcam/dist/style.css'
const uppy = new Uppy({
debug: true,

View file

@ -1,24 +1,21 @@
{
"name": "@uppy-example/php-xhr",
"version": "0.0.0",
"type": "module",
"dependencies": {
"@babel/core": "^7.4.4",
"@uppy/core": "workspace:*",
"@uppy/dashboard": "workspace:*",
"@uppy/webcam": "workspace:*",
"@uppy/xhr-upload": "workspace:*",
"babelify": "^10.0.0",
"budo": "^11.3.2",
"cookie-parser": "^1.4.6",
"cors": "^2.8.4",
"formidable": "^1.2.1",
"npm-run-all": "^4.1.3"
"@uppy/xhr-upload": "workspace:*"
},
"devDependencies": {
"npm-run-all": "^4.1.3",
"vite": "^3.0.0"
},
"private": true,
"scripts": {
"copy": "cp ../../packages/uppy/dist/uppy.min.css .",
"start": "npm-run-all --serial copy --parallel start:*",
"start:client": "budo main.js:bundle.js -- -t babelify",
"start:server": "mkdir -p uploads && php -S 0.0.0.0:3020"
"start": "npm-run-all --parallel start:server start:client",
"start:client": "vite",
"start:server": "mkdir -p uploads && php -S 0.0.0.0:3020 server.php"
}
}

View file

@ -1,3 +0,0 @@
flask
werkzeug
flask-cors

View file

@ -18,14 +18,14 @@ if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
exit(0);
}
if ($_POST && !empty($_FILES["files"])) {
$target_dir = './uploads/';
$target_file = $target_dir . basename($_FILES['files']['name'][0]);
if ($_POST && !empty($_FILES["file"])) {
$target_dir = __DIR__ . DIRECTORY_SEPARATOR . 'uploads';
$target_file = $target_dir . DIRECTORY_SEPARATOR . basename($_FILES['file']['name']);
try {
if (move_uploaded_file($_FILES['files']['tmp_name'][0], $target_file)) {
if (move_uploaded_file($_FILES['file']['tmp_name'], $target_file)) {
header('Access-Control-Allow-Origin: *');
header('Content-type: application/json');
$data = ['url' => $target_file, 'message' => 'The file ' . basename($_FILES['files']['name'][0]) . ' has been uploaded.'];
$data = ['url' => $target_file, 'message' => 'The file ' . basename($_FILES['file']['name']) . ' has been uploaded.'];
http_response_code(201);
echo json_encode($data);
} else {

View file

@ -8162,17 +8162,12 @@ __metadata:
version: 0.0.0-use.local
resolution: "@uppy-example/php-xhr@workspace:examples/php-xhr"
dependencies:
"@babel/core": ^7.4.4
"@uppy/core": "workspace:*"
"@uppy/dashboard": "workspace:*"
"@uppy/webcam": "workspace:*"
"@uppy/xhr-upload": "workspace:*"
babelify: ^10.0.0
budo: ^11.3.2
cookie-parser: ^1.4.6
cors: ^2.8.4
formidable: ^1.2.1
npm-run-all: ^4.1.3
vite: ^3.0.0
languageName: unknown
linkType: soft