Library Upload in WordPress

wiakc's picture
Forums: 

I've installed H5P plugin in my WordPress 5.3.2 under XAMPP on my local machine running macOS 10.15.3. Everything is working fine as is. The problem is when I try to upload a new library called greetingcard. I've created four files library.json, semantics.json, greetingcard.js, and greetingcard.css as per tutorial instructions. I've zip them individually (no directory) into greetingcard.zip using a native macOS compression tool. Then I've renamed the file to greetingcard.h5p and tried to upload the file to the library. Unfortunately, the file did not load giving me the following warnings:

Warning: scandir(/opt/lampp/htdocs/wp1/wp-content/uploads/h5p/temp/h5p-5e5435bfe434b): failed to open dir: No such file or directory in /opt/lampp/htdocs/wp1/wp-content/plugins/h5p/h5p-php-library/h5p.classes.php on line 934
Warning: scandir(): (errno 2): No such file or directory in /opt/lampp/htdocs/wp1/wp-content/plugins/h5p/h5p-php-library/h5p.classes.php on line 934
Warning: Invalid argument supplied for foreach() in /opt/lampp/htdocs/wp1/wp-content/plugins/h5p/h5p-php-library/h5p.classes.php on line 935

What is wrong? How can I fix it?

I am also experiencing this issue.

I am runnning a local Wordpress using XAMPP and trying to follow the greeting card tutorial. I also recieve the same error message (though file paths are my own).

I am also experiencing this issue.

I am runnning a local Wordpress using XAMPP and trying to follow the greeting card tutorial. I also recieve the same error message (though file paths are my own).

otacke's picture

Hi you two!

I am not sure what causing this particular issue, but in general, you should stick to the documentation for setting up a dev system. It recommends Drupal 7, which may not be ideal, but the H5P plugin for Drupal has some extra options making it way more suitable that WordPress for H5P development (no need to upload new library versions, no need to delete caches, etc.). Also, try to use the h5p cli tool for packing and possibly other tasks. Zipping H5P files manually can be glitchy.

Best,
Oliver

Is the glitchy-ness just inherent in using H5P with Wordpress? I have an online staging site as well that won't upload the Hello World .H5P package. however this time it just reloads the page and dosen't show any errors, and the library dosen't show up. If I can't upload custom libraries to Wordpress becuase of glitchy-ness it kind of defeats the purpose of me trying to develop packages for the site.

otacke's picture

Hi M-DSI!

It's not glitchyness in the sense of "things magically don't work" but your development/test process needs to be rigid or you may wonder why things don't work. The WordPress plugin simply wasn't designed for development, but using it to run H5P is more than fine regardless of where content types were developed.

Best,

Oliver 

Perhaps there is something wrong with the package itself? I do not have access to a Drupal site but I have tried uploading it to a staging Moodle site and am once again reciving the above errors. Does anything in the attached H5P file stand out as something that might be causeing the issue? Does the file work for you in your development system?

Attachments: 
otacke's picture

Hi M-DSI!

There is. The structure of a content type library file is different to that of a content file. Contents inside the archive should be in a folder using the naming convention H5P.MachinenName-majorversion.minorversion. So, here your contents should be in a folder named H5P.GreetingCard-1.0.

Also, if you want to keep your life complicated by not using h5p-cli (which using the Drupal development environment would only be required whenever you want to share your finished product, but not when developing and testing), make sure to use the D and X flag of the zip command. So, here you'd need something such as

zip -rDX foobar.zip H5P.GreetingCard-1.0/*

Best,
Oliver

Thanks otacke,

Placing the package files inside a folder with a matching MachineName was the step that I missed. I am now able to start experimenting with development. It seems like the errors both I and OP were expereinceing are related to not having the package packed correctly.

To help any future visitors this is the setup that made the errors go away:

H5P.GreetingCard.H5P (This is the zip file)
└── H5P.GreetingCard
    ├── greetingcard.js
    ├── greetingcard.css
    ├── library.json
    └── semantics.json