Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am looking into updating this template (http://templatic.com/demos/answers/?ptype=ask-a-question) which allows logged in subscribers to post (questions). I would like to add an option to upload a file and attach it to the post.

I was thinking of using the media-upload functionality, but I do not want to give users full access to the media library.

How could this be achieved?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

You won't find much on the Codex or the net about this. Media can seem like a pretty dark art, but everything you're looking for is in /wp-admin/includes/media.php.

The function you're looking for is media_handle_sideload(). You'll have to pass it a $file_array, which you'll have to read up on.

Basically you just make sure your file information is all up to snuff, pass it into this function and it creates something that acts a lot like a regular post and can be manipulated via the media tools and custom post queries with post_type=attachment argument.

share|improve this answer
    
aha! thank you! A dark art makes it sound intriguing. –  Bundarr Mar 18 '11 at 2:24
1  
NOTE: Did you mean wp-admin/includes/media.php and not wp-includes/media.php? –  t31os Mar 18 '11 at 9:47
    
That is what I meant. Thank you. Answer edited. –  editor Mar 18 '11 at 15:13
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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