If you want to import a local file from the server to MediaPress Gallery, we provide an api for it.
With MediaPress 1.3.6 and above, we have an API to import a local file from server directory to MediaPress .
mpp_import_file( $file, $gallery_id, $overrides = array() )
Parameters:-
- $file(required)(string):- Absolute path of the file to be imported.
- $gallery_id(required)(integer):- a valid MediaPress gallery id.
- $overrides(optional)(array):- Override any extra property of the media.
Return:-
media id on success or WP_Error object on failure.
Example:-
mpp_import_attachment(‘/home/xyz/whaever/nature.jpg, 32);
That will import nature.jpg file to our gallery. The status is inherited from the gallery. You can override it using the overrides array.
What Happens Internally:-
- We test if the file exists and is readable.
- We test for the validity of gallery
- If both are valid, we test if the media specified by the attachment is a valid type of media for MediaPress(e.g allowed file type).
- If all is well, we check that the gallery type can contain media of the given type.
- If we reach here, we copy the file to the MediaPress’s gallery directory.
- We create a new media and save the media details(title, type etc) to database.
- If everything goes well, return the media id which is same as the attachment id.
- If any of the above steps go wrong, we return an instance of WP_Error detailing the problem.