CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Threaded View

  1. #1
    Join Date
    Mar 2009
    Posts
    19

    Uploading file to mysql using php

    Hi,
    I'm beginner in php and i'm trying to upload files to mysql using php using the following code:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitled Document</title>
    </head>
    
    <body>
    
    <form method="post" enctype="multipart/form-data">
    <table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
    <tr> 
    <td width="246">
    <input type="hidden" name="MAX_FILE_SIZE" value="2000000">
    <input name="userfile" type="file" id="userfile"> 
    </td>
    <td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td>
    </tr>
    </table>
    </form>
    
    <?php
    if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
    {
    $fileName = $_FILES['userfile']['name'];
    $tmpName  = $_FILES['userfile']['tmp_name'];
    $fileSize = $_FILES['userfile']['size'];
    $fileType = $_FILES['userfile']['type'];
    
    $fp      = fopen($tmpName, 'r');
    $content = fread($fp, filesize($tmpName));
    $content = addslashes($content);
    fclose($fp);
    
    if(!get_magic_quotes_gpc())
    {
        $fileName = addslashes($fileName);
    }
    include 'library/config.php';
    include 'library/opendb.php';
    
    $query = "INSERT INTO upload (name, size, type, content ) ".
    "VALUES ('$fileName', '$fileSize', '$fileType', '$content')";
    
    mysql_query($query) or die('Error, query failed'); 
    include 'library/closedb.php';
    
    echo "<br>File $fileName uploaded<br>";
    } 
    ?>
    
    </body>
    
    </html>
    but i got the following errors:

    Warning: include(library/config.php) [function.include]: failed to open stream: No such file or directory in F:\wamp\www\PHP_Test1\upload.php on line 39

    Warning: include() [function.include]: Failed opening 'library/config.php' for inclusion (include_path='.;C:\php5\pear') in F:\wamp\www\PHP_Test1\upload.php on line 39

    Warning: include(library/opendb.php) [function.include]: failed to open stream: No such file or directory in F:\wamp\www\PHP_Test1\upload.php on line 40

    Warning: include() [function.include]: Failed opening 'library/opendb.php' for inclusion (include_path='.;C:\php5\pear') in F:\wamp\www\PHP_Test1\upload.php on line 40

    Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in F:\wamp\www\PHP_Test1\upload.php on line 45

    Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in F:\wamp\www\PHP_Test1\upload.php on line 45
    Error, query failed

    well i don't know how to get these files "(library/config.php)" "(library/opendb.php"
    Last edited by PeejAvery; March 22nd, 2009 at 03:15 PM. Reason: Added code tags.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured