• kardall

    (@kardall)


    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 upload

    form 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

    • This topic was modified 8 years ago by kardall.
Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    To use WP resources, your code needs to be within the WP code structure. This is not possible (without a dirty hack) when pages are directly requested. The request needs to come through the WP system. The easiest way to do this is to create a custom page template. Add a page based on this template. When one requests this page, the code on the template is executed.

    The only other possibilities are to send requests through admin-ajax.php or admin-post.php. You may see examples on the ‘net that require or include wp-load.php or other core files. This is the dirty hack I referred to. Doing it this way is Doing it Wrong?. Any plugins destined for the WP repository will be summarily rejected if this approach is used.

    Thread Starter kardall

    (@kardall)

    Yup, that’s exactly why I was asking ??

    I will have a look at the template thing and see how I can finesse it to work the way I want. ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Upload File, Parse it, and Insert Posts with Content’ is closed to new replies.