1

I'm trying to allow users to upload audio via form and HTTP POST request.

Here is the relevant form code, from my page-profile.php :

<form method="post" action="wp-content/themes/freelanceengine-child/audio_upload.php" enctype="multipart/form-data">
                              <input type="file" name="file" id="file" accept="audio/*">

But the browser never reaches my php file. I get the following error: The requested resource /profile/wp-content/themes/freelanceengine-child/audio_upload.php was not found on this server.

This profile directory is not in my site anywhere so I don't know why it is being prepended to the URL. I've tried restarted the server and experimenting with different URLs and browsers, but /profile is consistently being prepended.

If you have insight, please help me understand why this is happening. I can probably fix it if I know why it's broken.

On a side note, I assume a plugin would be the best way to do something like this, but honestly I've never worked with wordpress plugins, so I'm just sticking to what I know for now.

  • Is it simple WordPress site or you also have BuddyPress installed on it ? Also can you please share whats there in audio_upload.php file & where (in which template) have you added this form code? – Prasad Nevase Dec 30 '15 at 13:29
  • The page-profile template is in use here. It may be theme-specific. It's a wordpress site that uses a theme called Freelanceengine. No BuddyPress install here. The audio_upload.php at this point just checks the file size and moves it to a directory called audio-files for storage. – Keenan Diggs Dec 30 '15 at 13:33
1

You should not be using a relative URL. I've written a number of answers about this already Relative URLs are relative to the page you are on as the browser sees it. With pretty permalinks turned on that is almost always going to work out badly. This problem/mistake is so common that I guessed the answer just by looking at your title.

Second, you should not be submitting to a stand-alone theme file like that. Use the AJAX API (even if it isn't actually an AJAX request). It is very, very simple:

function my_ajax_wpse_213294() {
  // your upload code

  exit();
}
add_action('wp_ajax_my_ajax', 'my_ajax_wpse_213294'); // logged in only
add_action('wp_ajax_nopriv_my_ajax', 'my_ajax_wpse_213294');

Submit to /wp-admin/admin-ajax.php which can be created with admin_url('/admin-ajax.php'); with the ?action=my_ajax URL parameter.

  • Thank you for your suggestion. Can this be done without a plugin? Forgive my scrubbiness. – Keenan Diggs Dec 31 '15 at 21:29
  • Well, your code would have to be in a theme or a plugin (or mu-plugin) but the interface is built into WordPress. – s_ha_dum Dec 31 '15 at 21:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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