2

I've been testing the Wordpress Playground with my plugin. My plugin offers a way to upload a file to wp-content/uploads/ and it seems to work in the playground.

$file_name = $file['name'];
$temp_file = $file['tmp_name'];

//Move uploaded file to Wordpress upload folder
$upload_dir = wp_upload_dir();
$destination = $upload_dir['basedir'] . '/' . $file_name;
    

if (move_uploaded_file($temp_file, $destination)) 
{
    $file_url = $upload_dir['baseurl'] . '/' . $file_name;    
    echo json_encode( __('File uploaded successfully', 'csv-to-html') . ': ' . $file_url);
} 

The file uploaded successfully prints out and I see that file is in that location (I have a function that scans a folder (wp-content/uploads) and I see that the file exists there), but WHEN I try to read this file into an array I get a permission denied.

So I can write the file but I can't read it. The code is for reading is:

 //$file is path to wp-content/uploads/ with the actual filename 
 //included, e.g. wp-content/uploads/books.csv
 $arr_from_file = array_filter( file( $file, FILE_IGNORE_NEW_LINES ) ); 

This code works perfect locally and on other external sites. The plugin has 500+ active users, so I really don't know how to do a workaround to get this to work in the Wordpress playground. Thoughts?

1 Answer 1

1

I ran into this problem also with a plugin I am setting up a Playground Blueprint for.

What I found is that when the user attempts to upload an image via my plugin, the permissions on the file end up being 0000. Which of course can't be accessed. What I ended up doing is setting the permissions on the uploaded file to 0644 after it is uploaded.

I'm using a custom plugin that handles compatibility issues with Playground, so I added a handler function to it that sets the file permissions when an upload is completed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.