Site icon Hip-Hop Website Design and Development

Utilizing $_FILES variable into the identical perform for importing photos and information

I would like begin saying that I am studying and I am attempting to grasp the usage of $_FILES and $file_handler that are making me loopy into this perform to add attachments from a frontend kind.

What I’ve found into mine yesterday query was that utilizing $_FILES into the identical perform makes it overwritten so some good dude steered to alter this variable in one thing completely different like $no matter. Each information may very well be managed and uploaded then however after all this isn’t taking place but and solely information are uploaded. Having 2 kind inputs comparatively named:

Principally I’ve arrived at this level in my php:

if ($_FILES)
    {
        // Get the add attachment information
        $photos = $_FILES['moreimages'];
        foreach ($photos['name'] as $key => $worth)
        {
            if ($photos['name'][$key])
            {
                $picture = array(
                    'title' => $photos['name'][$key],
                    'sort' => $photos['type'][$key],
                    'tmp_name' => $photos['tmp_name'][$key],
                    'error' => $photos['error'][$key],
                    'dimension' => $photos['size'][$key]
                );

                //right here I've modified the $_FILES variable into one thing else
                $my_processed_images = array("moreimages" => $picture);
                foreach ($my_processed_images as $picture => $array)
                {
                    $newupload = project_images($picture,$pid);
                }
            }
        }
        // Get the add attachment information
        $information = $_FILES['morefiles'];
        foreach ($information['name'] as $key => $worth)
        {
            if ($information['name'][$key])
            {
                $file = array(
                    'title' => $information['name'][$key],
                    'sort' => $information['type'][$key],
                    'tmp_name' => $information['tmp_name'][$key],
                    'error' => $information['error'][$key],
                    'dimension' => $information['size'][$key],
                    'post_mime_type' => $information['type'][$key]
                );
                $_FILES = array("morefiles" => $file);
                foreach ($_FILES as $file => $array)
                {
                    $uploadfile = project_file($file,$pid);
                }
            }
        }
    }

and my capabilities appear to be

perform project_images($file_handler, $pid)
    {
        if ($_FILES[$file_handler]['error'] !== UPLOAD_ERR_OK) __return_false();
        require_once(ABSPATH . "wp-admin" . '/contains/picture.php');
        require_once(ABSPATH . "wp-admin" . '/contains/file.php');
        require_once(ABSPATH . "wp-admin" . '/contains/media.php');
        $image_id = media_handle_upload( $file_handler, $pid );
        return $image_id;
    }
perform project_file($file_handler, $pid)
    {
        if ($_FILES[$file_handler]['error'] !== UPLOAD_ERR_OK) __return_false();
        require_once(ABSPATH . "wp-admin" . '/contains/picture.php');
        require_once(ABSPATH . "wp-admin" . '/contains/file.php');
        require_once(ABSPATH . "wp-admin" . '/contains/media.php');
        $file_id = media_handle_upload( $file_handler, $pid );
        update_post_meta($file_id,'is_prj_file','1');
        return $file_id;
    }

I perceive that there may very well be an issue with my $file_handler however I do not know easy methods to handle it. What actually is occurring is that debugging the $more_images is null and never thought of and $_FILES into the second loop is uploaded as an alternative.
Are you able to drive me?

EDIT

My HTML kind fields are like these for whole:

<enter id="moreimages" settle for="picture/png, picture/jpeg, picture/gif" sort="file" title="moreimages[]" >

<enter id="morefiles" settle for=".zip,.pdf,.rar,.doc,.docx,.xls,.xlsx,.ppt,.pptx,.psd,.ai" sort="file" title="morefiles[]" >

Moreover My AJAX POST STATUS is OK sending these parameters for moreimages:

Content material-Disposition: form-data; title="moreimages[]"; filename="Display screen Shot 2016-04-05 at 16.48.10.png"
Content material-Sort: picture/png

PNG

and these parameters for morefiles:

Content material-Disposition: form-data; title="morefiles[]"; filename="articolo-slow-food-ararat.docx"
Content material-Sort: utility/vnd.openxmlformats-officedocument.wordprocessingml.doc

So I believe the issue, as soon as once more, how these information are acquired into php.