0

hello everyone this is my piece of code to upload the pdf file,file is not being uploaded to path i have given plz help me out in database its shows the entry but in the path where pdf file should be there it does not exist...

<?php
    // Check if a file has been uploaded
    if(isset($_FILES['uploaded_file'])) {
        // Make sure the file was sent without errors
        if($_FILES['uploaded_file']['error'] == 0) {
            // Connect to the database
            $dbLink = new mysqli('localhost', 'root', '', 'college');
            if(mysqli_connect_errno()) {
                die("MySQL connection failed: ". mysqli_connect_error());
            }

            // Gather all required data
            $id1 = $dbLink->real_escape_string($_FILES['uploaded_file']['down_id']);
            $id2 = $dbLink->real_escape_string($_FILES['uploaded_file']['course_id']);
            $data = $dbLink->real_escape_string(file_get_contents($_FILES  ['uploaded_file']['tmp_name']));
            move_uploaded_file($data,"/upload/syllabus/");
            $mypath="upload/syllabus/";
            $type = intval($_FILES['uploaded_file']['down_type']);

            // Create the SQL query
            $query = "
                INSERT INTO `download_master` (
                    `down_id`, `course_id`, `down_title`, `path`
                )
                VALUES (
                    '{$id1}', '{$id2}', {$type}, '{$mypath}'
                )";

            // 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 'An error accured while the file was being uploaded. '
               . 'Error code: '. intval($_FILES['uploaded_file']['error']);
        }

        // Close the mysql connection
        $dbLink->close();
    }
    else {
        echo 'Error! A file was not sent!';
    }

    // Echo a link back to the main page
    echo '<p>Click <a href="index.php">here</a> to go back</p>';
    ?>
Linus
  • 899
  • 3
  • 19
  • 33
  • Does `move_uploaded_file()` return `false`? http://stackoverflow.com/questions/845021/how-to-get-useful-error-messages-in-php –  Mar 04 '15 at 11:51
  • there were no warnings or error shown in browser window....... – Linus Mar 04 '15 at 11:54
  • 1
    That still doesn't tell what does `move_uploaded_file()` return (`$var = move_uploaded_file($data,"/upload/syllabus/"); echo $var;`). :) –  Mar 04 '15 at 12:01
  • i just used error_reporting(-1); ini_set('display_errors', 'On'); for debugging it shows undefined index down_id ,course_id etc.. – Linus Mar 04 '15 at 12:05
  • now i have come to know importance of debugging... :) – Linus Mar 04 '15 at 12:09
  • this is what finally i am getting Warning: file_get_contents(1) [function.file-get-contents]: failed to open stream: No such file or directory in C:\Web Project\xampp\htdocs\test\test3.php on line 17 Success! Your file was successfully added! – Linus Mar 04 '15 at 12:10

0 Answers0