Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

example: migrate php-xhr to ESM #4009

Merged
merged 1 commit into from
Aug 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 1 addition & 2 deletions examples/php-xhr/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
uppy.min.css
uploads
uploads/
10 changes: 5 additions & 5 deletions examples/php-xhr/readme.md → examples/php-xhr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
3 changes: 1 addition & 2 deletions examples/php-xhr/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
12 changes: 8 additions & 4 deletions examples/php-xhr/main.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
21 changes: 9 additions & 12 deletions examples/php-xhr/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
3 changes: 0 additions & 3 deletions examples/php-xhr/requirements.txt

This file was deleted.

10 changes: 5 additions & 5 deletions examples/php-xhr/upload.php → examples/php-xhr/server.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
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 {
Expand Down
7 changes: 1 addition & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down