[ASK] change fget function in PHP to wget function

Discussion in 'PHP' started by leksa, Oct 16, 2007.

  1. #1
    i need some help thats know how to change the fget function in my php to wget.

    Because the server not running fget. Just wget.

    If someone know, i will post the code line..

    Thanks for answer..

    Regards

    Leksa
     
    leksa, Oct 16, 2007 IP
  2. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #2
    'fget' is not a native PHP function. Either it's defined in your code somewhere else or you didn't write it properly here.

    A copy of a few lines of code and maybe a quick "this is what I'm trying to do" might help.
     
    TwistMyArm, Oct 16, 2007 IP
  3. tamen

    tamen Peon

    Messages:
    182
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #3
    tamen, Oct 16, 2007 IP
  4. leksa

    leksa Active Member

    Messages:
    432
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #4
    i used it to get CSV use fgetcsv...
    because i want a huge txt csv in sql table...

    But the server have not fget funtion in the server - that the admin said.
    He just pointed me to use wget, because have similar function..

    How to do this?

    I will ad some line from the code here..
    still open it..

    thanks for you all reply this :)
     
    leksa, Oct 16, 2007 IP
  5. leksa

    leksa Active Member

    Messages:
    432
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #5
    
    if(isset($_POST['csvSubmit']))
    {
    set_time_limit(0);
    
    $fp = fopen($dir.$_POST['csv'], "r");
    
    $data = fgetcsv($fp, 0);
    for($i = 1; ; $i++)
    {
    $data = fgetcsv($fp, 0);
    if($data === FALSE) break;
    
    for($j = 0; $j < count($data); $j++)
    $data[$j] = addslashes($data[$j]);
    
    // $data[0] = "parent3^^child1^^child11^^child10";
    $cats = explode("^^", $data[0]);
    
    $sql = "SELECT * FROM tblcategories WHERE CategoryName IN ('".implode("','", $cats)."') ORDER BY CategoryName";
    $catList = array();
    $result = mysql_query($sql);
    while($row = mysql_fetch_array($result))
    array_push($catList, $row);
    
    //echo "<pre>".print_r($catList, true).print_r($cats, true)."</pre>";
    
    $parent = 0;
    $insert = count($catList) == 0;
    foreach($cats as $cat)
    {
    $id = 0;
    if(!$insert)
    {
    $id = searchCat($catList, $cat, $parent);
    if($id == 0) $insert = TRUE;
    else $parent = $id;
    }
    if($insert)
    {
    $sql = "INSERT INTO tblcategories (CategoryName, ParentID) VALUES ('$cat', '$parent')";
    mysql_query($sql);// or die(mysql_error());
    $parent = mysql_insert_id();
    }
    }
    
    $data[0] = $parent;
    
    
    $sql = "INSERT INTO `tblservices` (`CategoryID`, `CompanyName`, `Address`, `Country`,
    `PhoneContacts`, `FaxNumbers`, `WebSites`, `EmailAddress`, `ContactNameAndPosition`,
    `Description`, `ProductsAndServices`, `TypeOfBussiness`, `YearsInBusiness`, `Employees`, `Income`)
    VALUES ('".implode("','", $data)."')";
    
    mysql_query($sql);// or die($sql."<br>".mysql_error());
    if($i % 1000 == 0) echo "$i data has been inserted -- ".date('m/d/Y G:i:s')."<br>";
    }
    echo ($i-1)." data has been inserted -- ".date('m/d/Y G:i:s')."<br><font color='green'>Complete!</font><br>";
    fclose($fp);
    }
    
    Code (markup):
     
    leksa, Oct 16, 2007 IP