Rodrigo Sasse
Rodrigo Sasse

Reputation: 21

Can't upload file using XAMPP

I have to create a CMS for a webstore for a webscript unit i'm taking. I have to upload a photo of the product but i keep getting and error when i try to upload. I search it a lot and tried a lot of things, i changed the folder to read & write, i did the 'chmod -R 777...', nothing. I'm starting to think the problem is with my code. I appreciate all help, thanks!

I always this error: Warning: File upload error - unable to create a temporary file in Unknown on line 0

<?php

    $dbhost = '127.0.0.1';
    $dbuser = 'root';
    $dbpass = '';
    $dbname = 'ezcart';

    $conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname);

    if ($conn->connect_error) {

        die("Could not connect to the database: " . $conn->connect_error);

    }

    $name = $_FILES['photo']['name'];
    $size = $_FILES['photo']['size'];
    $type = $_FILES['photo']['type'];
    $tmp_name = $_FILES['photo']['tmp_name'];

    if (isset($name)) {

        if(($type == 'image/jpeg' || $type == 'image/jpg' || $type = 'image/png') && ($size <= 3145728)) {

            $path = 'prod_photos/';

            if (move_uploaded_file($tmp_name, $path.$name)) {

                $sql = "INSERT INTO product (prodCat, prodDes, prodNam, prodPho, prodPri, prodSto, prodSup) VALUES ('$_POST[prodCat]', '$_POST[prodDes]', '$_POST[prodNam]', '$name', '$_POST[prodPri]', '$_POST[prodSto]', '$_POST[prodSup]')";

                if ($conn->query($sql) === TRUE) {

                    echo '<span>Product added sucessfully.</span>';

                }

            }

        }

        else {

            echo '<span>Please choose a valid photo.</span>';

        }

    }

    $conn->close();

?>

Upvotes: 1

Views: 9943

Answers (1)

Duyet Le
Duyet Le

Reputation: 187

You should check your php.ini and look for the 'upload_tmp_dir' option.

After that, check the permission of your tmp dir, and try to chmod it again.

If you want to know what upload_tmp_dir your server is using, you can simply use this:

die(ini_get('upload_tmp_dir') ? ini_get('upload_tmp_dir') : sys_get_temp_dir());

Upvotes: 1

Related Questions