SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist
    Join Date
    Dec 2006
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    getting info from text file the storing in mysql

    Hi Guys,

    i'm attempting to do this, allow users to upload text files, then echo out the data, so far it only echoes out the filename rather than the contents, is it possible to :

    open up the file, get the contents, save the contents in to mysql then echo it out?

    thanks for any help guys

    Graham

  2. #2
    SitePoint Enthusiast
    Join Date
    May 2007
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sure, this is pretty easy to do

    PHP Code:
    // Read content from the file
    $fileName '<put_your_filename_here>';
    $content file_get_contents($fileName);
    // Prepare it for storing in the database
    $content_to_save mysql_real_escape_string($content);

    // Save into the database
    $rowID = <put_your_row_id_here>;
    $query "INSERT INTO `my_table` (`id`,`content`) VALUES ('{$rowId}', '{$content_to_save}')";
    // It is supposed that mysql connection has been established
    mysql_query($query);

    // Output original content
    echo $content
    HTH

  3. #3
    SitePoint Evangelist
    Join Date
    Dec 2006
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Mate,

    Thanks for that it worked great

    Graham

  4. #4
    SitePoint Enthusiast
    Join Date
    May 2007
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Glad to help you


Bookmarks

Posting Permissions

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