-
Notifications
You must be signed in to change notification settings - Fork 406
trying to upload file to wordpress media fails in @php-wasm/universal 3.1.12 worked in @php-wasm/node 0.5.6 #3434
Copy link
Copy link
Open
Labels
[Type] BugAn existing feature does not function as intendedAn existing feature does not function as intended
Description
Prerequisites
- I have carried out troubleshooting steps and I believe I have found a bug.
- I have searched for similar bugs in both open and closed issues and cannot find a duplicate.
Describe the bug
try to upload media in wordpress running in node
Expected behavior
the media is uploaded and copied to wp-content/uploads
Actual behavior
fileInfos and addUploadedFile that were in @php-wasm/node 0.5.6 are not there anymore. I tried to use the $_FILES superglobal and then run php.request:
const uploadedFile = data.files["async-upload"];
// {
// key: "async-upload",
// name: "Yin_yang.png",
// size: 27700,
// type: "image/png",
// arrayBuffer: new Uint8Array([137, 80, ])
// }
const ext = path.extname(uploadedFile.name);
const vfsPath = `temp-${crypto.randomBytes(6).readUIntLE(0, 6)}${ext}`;
;
// 1. Write the actual data to the Wasm VFS
await php.writeFile(vfsPath, uploadedFile.arrayBuffer);
// 2. Mock the $_FILES superglobal
// This script runs BEFORE your target script
await php.run({
code: `<?php
$_FILES['async-upload'] = [
'name' => '${uploadedFile.name}',
'type' => '${uploadedFile.type}',
'tmp_name' => '${vfsPath}',
'error' => 0,
'size' => ${uploadedFile.size},
];
?>`
});it fails in php here
// A properly uploaded file will pass this test. There should be no reason to override this one.
$test_uploaded_file = 'wp_handle_upload' === $action ? is_uploaded_file( $file['tmp_name'] ) : @is_readable( $file['tmp_name'] );
if ( ! $test_uploaded_file ) {
return call_user_func_array( $upload_error_handler, array( &$file, __( 'Specified file failed upload test.' ) ) );
}Steps to reproduce
make a new post
set featured image
upload
Isolating the problem
- I have deactivated other plugins and confirmed this bug occurs when only this plugin is active.
- This bug happens with a default WordPress theme active.
- I can reproduce this bug consistently using the steps above.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
[Type] BugAn existing feature does not function as intendedAn existing feature does not function as intended
Type
Fields
Give feedbackNo fields configured for issues without a type.