Warning: file_get_contents(): Filename cannot be empty

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rian92
    New Member
    • Oct 2014
    • 5

    Warning: file_get_contents(): Filename cannot be empty

    Hi I would like to point out before I get into this that I am a PHP newb, and I have been struggling for a while. I'm trying this new script, but I got an error every time I did upload file.

    Warning: file_get_conten ts(): Filename cannot be empty in C:\Users\user\D esktop\xampp\ht docs\ubfm\d2.ph p on line 18

    Code:
    <?php
    // Check if a file has been uploaded
    if(isset($_FILES['uploaded_file'])) {
        // Make sure the file was sent without errors
        {
            // Connect to the database
            $dbLink = new mysqli('localhost', 'root', '', 'upload');
            if(mysqli_connect_error()) {
                die("MySQL connection failed: ". mysqli_connect_error());
            }
    // Gather all required data
    $name = &$_POST['name']; 
    $email = &$_POST['email']; 
    $subject = &$_POST['subject'];
    $department = &$_POST['department'];
    $message = &$_POST['message'];
    $mime = $dbLink->real_escape_string($_FILES['uploaded_file']['type']);
    $data = $dbLink->real_escape_string(file_get_contents($_FILES['uploaded_file']['tmp_name']));
    $size = intval($_FILES['uploaded_file']['size']);
           
     
            // Create the SQL query
            $query = "
                INSERT INTO `file`(Name,email,subject,department,message,mime,size,data,created)
                VALUES('$name','$email','$subject','$department','$message','$mime',$size,'$data', NOW()
                )";
     
            // Execute the query
            $result = $dbLink->query($query);
     
            // Check if it was successfull
            if($result) {
                echo 'Success! Your file was successfully added!';
            }
            else {
                echo 'Error! Failed to insert the file'
                   . "<pre>{$dbLink->error}</pre>";
            }
        }
       
     
    }
    else {
        echo 'Error! A file was not sent!';
    }
     
    // Echo a link back to the main page
    echo '<p>Click <a href="d1.php">here</a> to go back</p>';
    ?>
  • iam_clint
    Recognized Expert Top Contributor
    • Jul 2006
    • 1207

    #2
    Is your file input named uploaded_files?

    Comment

    • rian92
      New Member
      • Oct 2014
      • 5

      #3
      Hi iam_clint,
      Yes that my input name.

      Comment

      Working...