mirror of
https://github.com/transloadit/uppy.git
synced 2026-07-28 12:37:00 +00:00
example: migrate php-xhr to ESM (#4009)
This commit is contained in:
parent
8ac6091e1a
commit
655b8ba61b
9 changed files with 32 additions and 40 deletions
|
|
@ -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',
|
||||
|
|
|
|||
3
examples/php-xhr/.gitignore
vendored
3
examples/php-xhr/.gitignore
vendored
|
|
@ -1,2 +1 @@
|
|||
uppy.min.css
|
||||
uploads
|
||||
uploads/
|
||||
|
|
|
|||
|
|
@ -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
|
||||
```
|
||||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +0,0 @@
|
|||
flask
|
||||
werkzeug
|
||||
flask-cors
|
||||
|
|
@ -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 {
|
||||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue