[wp-hackers] Allow users to upload their own images - hook to use?

Gregory Lancaster greglancaster71 at gmail.com
Thu Sep 12 19:10:54 UTC 2013


I have no idea how I would insert that into $ _POST.  It wont take it, says
its an array.  I tried it.  Would you (JD) link me to a reference that
would explain how $_POST can work with variables in this way?


On Thu, Sep 12, 2013 at 11:46 AM, J.D. Grimes <jdg at codesymphony.co> wrote:

> > Yea a couple people on stack overflow told me the same about
> > insert_attachment returning the post ID of the attachment, that I dont
> > deny.  I just dont see how I can post it with the other form data.  Only
> > way I can think is a session.  I tried a variable within the value of the
> > input field but obviously that failed immediately since it has no value
> > until after the file is uploaded.
>
> Well, I'm not sure I understand what the problem is. Both the attachment
> and your data are being inserted on form submit, as per the code you
> posted. And the attachment is inserted before your custom data. So there is
> no problem there. Get the ID from the $newupload variable:
>
> > ///SUBMIT FORM CODE
> >
> > $post_id = NULL;
> > global $wpdb;
> > if ($_FILES) {
> >  foreach ($_FILES as $key => $value) {
> >    $newupload = insert_attachment($file, $post_id);
> >    /****** $newupload returns the attachment id of the file that *****/
> >    // was just uploaded. Do whatever you want with that now.
> >
> >
> > if (isset($_POST['submit'])) {
> > $wpdb->insert(wp_jo_plugin_options, array (
> >    'user_id' => $_POST['user_id'],
> >    'length'  => $_POST['length'],
> >    'ground'  => $_POST['ground'],
> >    'date'    => $_POST['date'],
> > 'file' => $_FILES['file'],
> > ));
> >        }
> >    }
> > }
>
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list