Upload File, Parse it, and Insert Posts with Content
-
So I am messing around with uploading files to WordPress, but I want to do something different.
Current setup:
I have a page created called upload-playlist
when it is accessed, it checks the default index.php file and I have a if the page is ‘upload-playlist’ do something specific.It would include a PHP file that contained a form where the user could upload an m3u playlist file, and when submitted would get parsed by another php file on the server. It would just ‘echo’ the response, and that echo’d response is captured back with the jQuery form submit.
then a div html is set to the response data from the form. This works fine.
First Attempt
I wanted to (in my processing php file) take the string that is generated, and do a wp_insert_post() using values like:
$postvalues = array( 'post_type' => 'kplm_song', 'post_status' => 'published', 'post_author' => wp_get_current_user_id(), 'post_title' => $song_title_and_artist );
However, whenever I use any wp_* functions, it throws a 500 internal server error. I have no access to the wordpress functions inside this php file, probably because it’s not a “function” as included in my functions.php
Section Attempt:
I have copied the functionality of the actual parsing, in an attempt to post the form data to itself and somehow retrieve the $_FILES information to do inside the header.php file, but it keeps telling me 404 not found. I am only thinking it has something to do with the rewrite for the files.
So maybe I am approaching this the wrong way, but in the end I have the following:
Custom Post Type: kplm_song / rewrite = ‘songs’
m3u with 3 songs saved for testing that I uploadform works fine, uploading file, but retrieving the data I am having an issue with when it is NOT a ‘action’ target. I don’t want to reload the page if I can help it, so if i could figure out a way (or someone know show) to have access to the wordpress wp_insert_post() function and wp_get_current_user_info() and such… that’d be great ;s
- The topic ‘Upload File, Parse it, and Insert Posts with Content’ is closed to new replies.