0

My code worked perfectly when all i was doing was upload files into the database. But when i tried to store it also in folder, i'm getting a warning:

Warning: move_uploaded_file(): Unable to move 'F:\xammp\xammp\tmp\php34C9.tmp' to 'uploads/' in F:\xammp\xammp\htdocs\custom-cms-praktis\main.php on line 47

I think I'm missing something important but i cant figure out what -_- here is my code:

<?php
$server = "localhost";
$user = "root";
$password = "";
$db = "cms_development";

$conn = new mysqli($server,$user,$password,$db);


if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
if (isset($_POST['username']) && isset($_POST['submit'])) {

    $fileName = $_FILES['file']['name'];
    $tmp_name = $_FILES['file']['tmp_name'];
    $fileSize = $_FILES['file']['size'];
    $fileType = $_FILES['file']['type'];
    $author = $_POST['username'];
    $email = $_POST['email'];

    $fp = fopen($tmp_name, 'r');
    $content = fread($fp, fileSize($tmp_name));
    $content = addslashes($content);
    fclose($fp);

    if (!get_magic_quotes_gpc()) {
        $fileName = addslashes($fileName);
    }

    if (move_uploaded_file($_FILES["file"]["tmp_name"], "uploads/")) {

        $query = "INSERT INTO upload (name, size, type, content, author, email ) ".
            "VALUES ('$fileName', '$fileSize', '$fileType', '$content', '$author', '$email')";

        mysql_query($query) or die('Error, Bad Query');

    } else {

        echo "Sorry, there was an error uploading your file.";

    }

}
?>

    <form method="post" action="" enctype="multipart/form-data">
        <input type="text" name="username" value="" placeholder="Name">
        <input type="text" name="email" value="" placeholder="Email">
        <input type="hidden" name="MAX_FILE_SIZE" value="2000000">
        <input type="file" name="file">
        <input type="submit" value="Submit" name="submit">
    </form>
</div>

Im working on local

codeplus
  • 21
  • 5
  • Possible duplicate of [PHP Warning: move\_uploaded\_file() unable to move](http://stackoverflow.com/questions/13723174/php-warning-move-uploaded-file-unable-to-move) – B001ᛦ Aug 31 '16 at 07:42
  • are you sure about the directory /uploads. check this created or not or permission issue or may be code file and uploads/ in same directory. – Yagnik Detroja Aug 31 '16 at 08:00
  • @YagnikDetroja , lol, the folder name was "upload" not "uploads". cant believe i missed something like that. that was a bit embarrassing, but thanks anyway – codeplus Sep 01 '16 at 01:38
  • 1
    @codeplus ok great but you write the path as "uploads". if folder name upload then why you try to move your file in "uploads". check this in your code. if (move_uploaded_file($_FILES["file"]["tmp_name"], "uploads/")) { Read your code carefully then laugh on other. – Yagnik Detroja Sep 01 '16 at 04:46

1 Answers1

-1

check if folder "uploads/" exists

if You don't know in what directory You are working use echo getcwd(); to print it

i think it should be in that dir: F:\xammp\xammp\htdocs\custom-cms-praktis\uploads

Aleksander
  • 16
  • 3