SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Upload data from local CSV to remote DB

    PHP Code:
    <form enctype="multipart/form-data" action="process_file.php" method="POST">
    <
    input type="hidden" name="MAX_FILE_SIZE" value="50000" />
    Choose a file: <input name="uploadedfile" type="file" /><br />
    <
    input type="submit" value="Process this file" />
    </
    form>  
    //
    $nsf=$_FILES['uploadedfile']['name'];  //name of file
    //
    $fp=fopen($nsf'rb');
    //if there is no file 
    if (!$fp)
    {
        echo 
    "<font color='#FF0000' >Can't find <b>$nsf</b> here!</font>";
        exit;

    Hi to all. I need to upload occasionally a small part of data from my PC to remote DB on Web. Problem is that name of that name of the CSV file isn't always same, so I used a script that is working fine on my computer in local environment (PHP 4.4.2 & MySQL 5 & Apache 2.0.55) but problem is that php script is working fine if CSV file is inside Apache's virtual folder where scripts are! If I try to pick a one CSV file from different position on my local disk I got error that can't find file!? I uploaded this script on my remote web site and tried again but same error happened. Length of CSV is max. up to 20 kB.
    It seems to me that I must at first to upload CSV file into folder of web server on Web and then to read from it..? As I'm using free php & MySQL server on Web it's impossible and uncomfortable...
    I thought that this thing is simple: pick a file, detect his name, read it, explode into fields and insert fields into table of DB...
    But it looks no more so simply. What now?

  2. #2
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Simply search for SQL query "LOAD DATA FILE..." which allow you to get data inserted to the database table from CSV.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  3. #3
    SitePoint Member
    Join Date
    Aug 2007
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy That's OK but...

    Thanks for your response.
    Problem with LOAD DATA INFILE is that there is possible appearing of rows that already exist in table; it would then lead to duplication information in table. I would like to check data in CSV file before inserting into table.
    It would be nice if I could load data at least in some array or variable for check before inserting or so... just to inform a user that in inserted data were duplicated data that removed from inserting process...
    Since few days I tried to find out good solution but...nop.


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
  •