Worthless temporary directory when uploading images

Asked

Viewed 76 times

0

Hello, in my application I have an upload of multiple images, with almost all images works perfectly, however in 1 image I had a problem and probably should happen more times in the future, so it is better to try to solve now.

The problem is that when uploading this image it registers in the database normally, but does not move to the uploads folder like all the others, debugging the code found that its temporary file does not exist, so the code tries to search for it to move, but does not find, then do nothing.

I am using Xampp, the temporary folder of xampp is: C: xampp tmp file.tmp

Code:

        // Get Images Informations

        $image_name = $_FILES['galeria']['name'];
        $image_dir = $_FILES['galeria']['tmp_name'];

        // Upload Directory
        $upload_dir = '../../../_main/uploads/';

        // Start Count
        $i = 0;

        while($i <= count($_FILES['galeria']['name'])) {
            // Allowed Extensions

            $extensions = array('png', 'jpg', 'jpeg');

            // Get Image Extension

            $img_ext = strtolower(pathinfo($image_name[$i], PATHINFO_EXTENSION));

            if(!in_array($img_ext, $extensions)) {
                header('Location: /new_product');
                $_SESSION['erro'] = 'img_ext';
                exit();
            }else {
                // New Image Name

                $new_image_name = mt_rand(1000, 1000000).'.'.$img_ext;

                // Move Image to Folder

                move_uploaded_file($image_dir[$i], $upload_dir.$product_id.'/'.$new_image_name);

                // Insert into DB

                $insert_step_2 = $pdo->prepare('INSERT INTO imagens_produtos (nome, id_produto) VALUES (:nome, :id_produto)');
                $insert_step_2->execute(array(
                    ':nome' => $new_image_name,
                    ':id_produto' => $product_id
                ));
            }

            $i++;

            if($i >= count($_FILES['galeria']['name'])) {

                // Return do New Product Page
                //header('Location: /new_product');
            }
        }

Output from var_dump

array(5) { ["name"]=> array(1) { [0]=> string(11) "okokoko.jpg" } ["type"]=> array(1) { [0]=> string(0) "" } ["tmp_name"]=> array(1) { [0]=> string(0) "" } ["error"]=> array(1) { [0]=> int(1) } ["size"]=> array(1) { [0]=> int(0) } }

Image occurring the error:

https://imgur.com/a/yM5ImvG

  • Do var_dump($_FILES); exit; in PHP, send the image giving the problem and add in the question the output generated on the screen.

  • I added the information

  • I just realized the empty type...

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.