PHP - Looping To Read A Csv File
I need some assistance in trying to resolve some issue I have with some code. Currently when I click on an upload button, this should read my csv file and the put the data into phpmyadmin but after looking around various forums and websites I still can not seem to get this to work any assistance would be appreciated. <?php $db = new mysqli('localhost','root','',''); if ($db->connect_errno) { echo "Failed to connect to MySQL: " . $db->connect_error; exit(); } ?> <t<html> <head> <title>Local Care Direct </title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" crossorigin="anonymous"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" crossorigin="anonymous"> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" crossorigin="anonymous"></script> </head> <body> <form method="POST" enctype="multipart/form-data" action="<?php echo $_SERVER["PHP_SELF"]; ?>"> <div align="center"> <p>Select CSV file: <input type="file" name="file" /></p> <p><input type="submit" name="csv_upload_btn" value="Upload" /></p> </div> </form> <table align="center" width="800" border="1" style="border-collapse:collapse; border:1px solid #ddd;" cellpadding="5" cellspacing="0"> <thead> <tr bgcolor="#FFCC00"> <th>test</th> <th>test</th> <th>test</th> <th>test</th> <th>test</th> <th>test</th> <th>test</th> <th>test</th> <th>test</th> <th>test</th> <th>test</th> <th>test</th> <th>test</th> <th>test</th> <th>test</th> <th>test</th> <th>test</th> <th>test</th> <th>test</th> <th>test</th> <th>test</th> <th>test</th> <th>test</th> <th>test</th> <th>test</th> <th>test</th> <th>test</th> <th>test</th> <th>test</th> <th>test</th> <th>test</th> <th>test</th> </tr> </thead> <tbody> <?php // Create database $sql = "CREATE DATABASE IF NOT EXISTS csv"; if (mysqli_query($db, $sql)) { echo "Database created successfully";//confirmation message } else { echo "Error creating database: " . mysqli_error($db);//error message and reason mysql or php mysqli_close($db); } //define the database to use $sql = "Use `csv`"; if (mysqli_query($db, $sql)) { echo " Use csv successfully";//confirmation message } else { echo " Error use csv: " . mysqli_error($db);//error message and reason mysql or php mysqli_close($db); } //create the table in the database $sql = "CREATE TABLE IF NOT EXISTS`csvfile` ( `Test` varchar(10) DEFAULT NULL, `Test` varchar(5) DEFAULT NULL, `Test` varchar(10) DEFAULT NULL, `Test` varchar(5) DEFAULT NULL, `Test` varchar(77) DEFAULT NULL, `Test` varchar(4013) DEFAULT NULL, `Test` varchar(16) DEFAULT NULL, `Test` varchar(16) DEFAULT NULL, `Test` varchar(5) DEFAULT NULL, `Test` varchar(10) DEFAULT NULL, `Test` varchar(10) DEFAULT NULL, `Test` varchar(5) DEFAULT NULL, `Test` varchar(10) DEFAULT NULL, `Test` varchar(16) DEFAULT NULL, `Test` varchar(22) DEFAULT NULL, `Test` varchar(16) DEFAULT NULL, `Test` varchar(22) DEFAULT NULL, `Test` varchar(10) DEFAULT NULL, `Test` varchar(10) DEFAULT NULL, `Test` varchar(10) DEFAULT NULL, `Test` varchar(10) DEFAULT NULL, `Test`varchar(10) DEFAULT NULL, `Test` varchar(10) DEFAULT NULL, `Test` varchar(10) DEFAULT NULL, `Test` varchar(10) DEFAULT NULL, `Test` int(8) DEFAULT NULL, `Test` varchar(5) DEFAULT NULL, `Test` varchar(5) DEFAULT NULL, `Test` varchar(5) DEFAULT NULL, `Test` varchar(5) DEFAULT NULL, `Test` varchar(5) DEFAULT NULL, `Test` varchar(5) DEFAULT NULL, `Test` varchar(5) DEFAULT NULL, `Test` varchar(5) DEFAULT NULL, `Test` varchar(5) DEFAULT NULL, `Test` varchar(5) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; "; if (mysqli_query($db, $sql)) { echo " table created successfully";//confirmation message } else { echo " Error creating table: " . mysqli_error($db);//error message and reason mysql or php mysqli_close($db); } //in case of data already in the csvtable, delete the data $sql = "DELETE FROM `csvfile`"; if (mysqli_query($db, $sql)) { echo " deleted data from the table successfully "; //confirmation message } else { echo " Error deleting data from the table: " . mysqli_error($db); //error message and reason mysql or php mysqli_close($db); } //do not delete //Process form if(isset($_POST["csv_upload_btn"])) $file = fopen("csv3.csv","r")or die("Failed to read file"); print_r(fgetcsv($file))== NULL; for ($i = 0; $row = fgetcsv($file); ++$i) { } fclose($file); /* $db->query('INSERT INTO `csvfile`(`Test`, `Test`, `Test`, `Test`, `Test`, `Test`, `Test`, `Test`, `Test`, `Test`, `Test`, `Test`, `Test`, `Test`, `Test`, `Test`, `Test`, `Test`, `Test`, `Test`, `Test`, `Test`, `Test`, `Test`, `Test`, `Test`, `Test`, `Test`, `Test`, `Test`, `Test`, `Test`, `Test`, `Test`, `Test`, `Test`) VALUES ("'.$row[1].'","'.$row[2].'","'.$row[3].'","'.$row[4].'","'.$row[5].'","'.$row[6].'","'.$row[7].'","'.$row[8].'","'.$row[9].'","'.$row[10].'","'.$row[11].'","'.$row[12].'","'.$row[13].'","'.$row[14].'","'.$row[15].'","'.$row[16].'")'); if($n>1){ */ ?> <tr> <td><?php echo $row[0];?></td> <td><?php echo $row[1];?></td> <td><?php echo $row[2];?></td> <td><?php echo $row[3];?></td> <td><?php echo $row[4];?></td> <td><?php echo $row[5];?></td> <td><?php echo $row[6];?></td> <td><?php echo $row[7];?></td> <td><?php echo $row[8];?></td> <td><?php echo $row[9];?></td> <td><?php echo $row[10];?></td> <td><?php echo $row[11];?></td> <td><?php echo $row[12];?></td> <td><?php echo $row[13];?></td> <td><?php echo $row[14];?></td> <td><?php echo $row[15];?></td> <td><?php echo $row[16];?></td> <td><?php echo $row[17];?></td> <td><?php echo $row[18];?></td> <td><?php echo $row[19];?></td> <td><?php echo $row[20];?></td> <td><?php echo $row[21];?></td> <td><?php echo $row[22];?></td> <td><?php echo $row[23];?></td> <td><?php echo $row[24];?></td> <td><?php echo $row[24];?></td> <td><?php echo $row[26];?></td> <td><?php echo $row[27];?></td> <td><?php echo $row[28];?></td> <td><?php echo $row[29];?></td> <td><?php echo $row[30];?></td> <td><?php echo $row[31];?></td> <td><?php echo $row[32];?></td> <td><?php echo $row[33];?></td> <td><?php echo $row[34];?></td> <td><?php echo $row[35];?></td> </tr> <?php //} //++; //} //fclose($handle); ?> </tbody> </table> </body> </html> Before I upload the file I get the following errors
The uploaded file contains dates, time, blank fields, true and false and text. I will need to prevent sql injection and html entities like ampersand sign. After uploading the file, it only reads the first line of my csv file which contains the title of each column and nothing is put into phpmyadmin Similar TutorialsI am using apache web server on linux. I am using PHP for web designing. On web server, i want to show the configuration data by reading the ini file. I am creating this ini file from one php code itself. If this php code i run through linux terminal, the file is created with file and group owner as root.(i am having sudo rights on machine) Then if i try to read the ini file from my apache web server, it gives warning as failed to open stream: permission denied. I have tried changing the owner, and permissions to 777 of the file. Still it is not readable.
On the other hand, if i run the php code of ini file creation through web server, ini file is created with file and group owner as apche. and web server is able to read/ write the file.
But i want to create that file from root or some other user and later read/written by apache.
How to give this access permission?
Hi there, I have an xml file which actually hold the currency conversion information which I downloaded from xe.com In the xml, the currency section snapshot looks like this: <currency> <csymbol>EUR</csymbol> <cname>Euro</cname> <crate>0.713</crate> <cinverse>1.403 </cinverse> </currency> this is the conversion of USD to Euro. And it tells how much is 1USD gonna be in Euros. i.e 1 USD = 0.713 EUR I have a product page on my website having the rates shown in USD. For the visitor is accessing the page from Europe it has to show the converted price in Euros. My application can detect the visitors country if hes accessing the page from Europe so that is not a problem. I just need to read the xml file and display the converted price based on the rates in the xml file. How can I read the xml file and output the price in Euros based on the rate. Thank you. All comments and feedbacks are always welcome how can I make php read a file with ids in the format 23423423 32423423 23423454 56667777 and output each id to $id[]? [LIST=1] CSV File Reading Displaying CSV file: Clicking the Show Logfile.txt link at the top of the page should display the CSV records inside logfile.txt Displaying CSV records formatted : Clicking the Show logfile.txt Formatted should display the CSV records formatted in an HTML table is descending order (more recent records are at the top). Use this function to convert CSV records back to an array : fgetcsv() I have most of this done and the problem I'm having is trying to read what I put into the file. (I hard coded what should go into the file). Could you tell me what I'm doing wrong and what I should do to fix it? Code: [Select] <? if ($_POST['_act'] = 'csv'): $fp = fopen('logfile.txt', 'a'); while (($data = fgetcsv($fp, 1000, ",")) !== FALSE){ print_r($data); } fclose($fp); endif; if ($_SERVER['REQUEST_METHOD'] == 'POST'): if (empty($_POST['fullname'])): $errMsg['fullname'] = "Please fill in Your Full Name."; endif; if (ereg("'Mr\. '", $_POST['fullname']) == false): $errMsg['fullname'] = "Please fill in Your Full Name."; endif; print_r($errMsgs); echo count($errMsgs); if (count($disperrMsgs > 0)): $dispErrMsgs = true; else: $fp = fopen('logfile.txt', 'a'); $fputcsv($fp, array("test", "lol", "roool")); fclose($fp); $dispSuccessMsg = true; endif; endif; ?> <html> <head> <style type="text/css"> h1 {color:red} div.error {border: 1px solid red; margin: 20px; padding: 20px; width: 400px} table {border: 1px solid #CCC; margin: 20px; border-collapse: collapse;} td, th {border: 1px solid #DDD; padding: 2px} th {background-color:#363; color: white} td.error {color:red} div.success {border: 1px solid green; margin: 20px; padding: 20px; width: 400px; color:green} </style> </head> <body> <h1> Form Validation Lab with Reg Expressions </h1> <p><a href="<?= $_SERVER['PHP_SELF'] ?> ">Refresh This Page</a> | <a href="./logfile.txt">Show Logfile.txt</a> | <a href="<?= $_SERVER['PHP_SELF'] ?>?_act=csv">Show logfile.txt Formatted</a> <a href="<?= $_SERVER['PHP_SELF'] ?>?_act=clear">Clear logfile.txt </a></p> <? if ($dispErrMsgs): ?> <div class="error"> <p>There are errors in the code: </p> <ol> <? foreach($errMsg as $errMsgs ): ?> <li><?= $errMsgs ?></li> <? endforeach; ?> </ol> </div> <? endif; ?> <? if ($dispSuccessMsg): ?> <div class="success"> <p>Thank you for your submission. </p> </div> <? endif; ?> <form action="<?= $_SERVER['PHP_SELF'] ?>" name="getstuff" method="post" > <input type="hidden" name="_act" value="post"> <table cellspacing = "0"> <tr> <th width="78">Full Name:</th> <td width="184"><input name="fullname" type="text" class="textbox" value="<? $_POST['fullname']; ?>" size="20" ></td> <td width="626" >Salution of Mr. or Mrs. followed by two text strings separated by any number of spaces. </td> </tr> <tr> <th>Street:</th> <td><input name="street" type="text" class="textbox" value="<? $_POST['street']; ?>" size="30"></td> <td >2 or 3 digit number followed by a text string ending with Street or Road separated by any number of spaces. </td> <tr> <th>Phone:</th> <td><input name="phone" type="text" class="textbox" value="<? $_POST['phone']; ?>" size="20"></td> <td >10 digits, first 3 digits have optional parentheses, either side of digits 456 are optional space, dot or hyphen. </td> </tr> <tr> <th>PostalCode:</th> <td><input name="postcode" type="text" class="textbox" value="<? $_POST['postcode']; ?>" size="8" maxlength="8"></td> <td > Postal Code: Char Char Digit Hyphen/space Char Digit Digit (No XYZ or 0's. Case insensitive. )</td> </tr> <tr> <th>Email:</th> <td><input name="email" type="text" class="textbox" value="<? $_POST['email']; ?>" size="25" maxlength="40"></td> <td > Must accept as a minimum : a@b.com</td> </tr> </table> <input name="reset" type='button' class="button" value='RESET' onClick="location.href = location.href"> <input name="_submit" type="submit" class="button" value="Submit me now!!!" > </form> <p id="notice">Everything below here is for testing purposes Don't remove this from your lab as I will use these buttons to fill your form with good and bad data as I mark it.</p> <script> az=document.getstuff; function goodstuff(){ az.fullname.value=" Mr. Joe Smith "; az.street.value="135 Fennell Road "; az.phone.value="905-575.1212"; az.postcode.value="Ln9-T23"; az.email.value="jsmith@gov.ca"; } function goodstuff2(){ az.fullname.value=" Mrs. Josephine Smith "; az.street.value=" 13 Fennell Street"; az.phone.value=" (905)-575.1212 "; az.postcode.value=" Ln9 T23"; az.email.value=" jsmith@gov.ca "; } function badstuff(){ az.fullname.value="Miss Josephine Smith"; az.street.value="1 Somewhere Avenue"; az.phone.value="905575122"; az.postcode.value="Z8N 3T2"; az.email.value="jsmith$gov#ca"; } function badstuff2(){ az.fullname.value=" Joe Smith "; az.street.value=" 1392 Fennell Street"; az.phone.value="[905] 575-1212"; az.postcode.value=" Ly9 T20"; az.email.value=" @jsmith$gov#ca"; } function goodandbad(){ az.fullname.value="Mrs. Joe"; az.street.value=" 135 Fennell Avenue West"; az.phone.value="905:5751212"; az.postcode.value=" L99-T23"; az.email.value=" jsmith@.gov.ca "; } </script> <form> <input type=button class="button" onClick="goodstuff();" value="Fill form with good values " length=100 > <input type=button class="button" onClick="goodstuff2();" value="Fill form with good values 2 " > <input type=button class="button" onClick="badstuff();" value="Fill form with BAD values "> <input type=button class="button" onClick="badstuff2();" value="Fill form with BAD values 2 "> <input type=button class="button" onClick="goodandbad();" value="Fill form with Good and BAD values 2"> <br> </form> </BODY> </HTML> I have a script which creates a Thumbnail image if one does not exists, the problem is i keep getting this error: Catchable fatal error: Object of class SimpleImage could not be converted to string in /homepages/22/d378569747/htdocs/scripts/primary_image.php on line 21 i have checked the logs and i think its a read error because the the image is already in use by the server if i remove (!file_exists("$root/thumnail_user_images/$image")) the script work fine, is there anyway to stop this error occuring? <?php //header('Content-Type: image/jpeg'); $root = $_SERVER['DOCUMENT_ROOT']; require("$root/include/mysqldb.php"); //mysql login details require("$root/include/mysql_connect.php"); //mysql connect $uin = $_GET['uin']; $result = mysql_query("SELECT * FROM Reg_Profile_images WHERE UIN='$uin' AND `primary` = '1' LIMIT 1"); while($row = mysql_fetch_array( $result )) { $image = $row[2]; if (!file_exists("$root/thumnail_user_images/$image")) { require("$root/include/image_resizing_function.php"); //create image $image = new SimpleImage(); $image->load("$root/raw_user_images/$image"); $image->resizeToWidth(250); $image->save("$root/thumnail_user_images/$image"); $image->output(); } else { readfile("$root/thumnail_user_images/$image"); } } //End Image file ?> Hi, I have a Excel File Reader script that works perfectly on my private development hosting, the Excel file is read and then the contents are displayed to the page with the help of a for loop. The trouble is when I try it out on my work's hosting space the script does nothing, no error messages or anything. I have not changed anything and all paths ect are correct. What else could be causing this? Many Thanks, Hello, I'm trying to read the first line of some large files by PHP, which means, the ideal solution does not work: Quote $content = file($file_import); $fields = explode(",", $content[0]); Quote Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 110 bytes) in C:\wamp\www\exchange\admin\import.php on line 55 Is there any other way to read only the first line without opening the whole file? Thanks!! im looking for a cool code to read file content of a file in a remote server i have a file called online.php that have this commands <?php echo (exec('netstat -a -n |find "5816" |find "ESTABLISHED" /c')-2); ?> i wanna have another file in my own host to read the content of this file from the remote server anyone have an idea ? Hi, I assigned a project where i have to import the mobile numbers from the file, but i have no idea how to proceed this. What kind of file to accept as input and how to read. Thanks Hello, I'm requesting your help here cause I'm really confused. I'm looking for deleting entries when an image doesn't load on my links test. I got all my links in a .txt file like this : links.txt = Code: [Select] <div class="gallery"> <a href="http://www.website.com/page"> <img src="http://tc16.easythumbhost.com/image.jpg" onerror="ImgError(this)"/> </a> </div> #enddiv the "onerror" code in img src sends an "Image Missing" pic. What I'd want is to change the "onerror" function to open a php script which deletes all the lines of the div. This is the script I use to show the links on my page : Code: [Select] $links = "links.txt"; $fd = fopen ($links, "r"); $content = fread ($fd,filesize ($links)); fclose ($fd); $delimiter = "#enddiv"; $splitcontent = explode($delimiter, $content); $output = array_slice($splitcontent, 0,100); foreach ( $output as $divs ) { echo "$divs"; } I've searched hours and tried lots of codes before posting Help would be very appreciated. Thanks. First, my goals: - The user selects a text file on their local PC (or their local network drive) to process. - I want to read the file into an array and process it. I'm having trouble with this. Here is my code so far: <?php session_start(); $title='Import File v.10a'; ?> <!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" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <?php echo '<title>'.$title.'</title>'; ?> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <?php require_once('navmenu.php'); echo '<h2>'.$title.'</h2>'; ?> <!-- comment --> <?php // Connect to the database $dbc = mysqli_connect($host, $user, $password, $database); $errcnt=0; $models=array(); //Init array $bullarr=array(); $model=''; $partname=''; $partsubname=''; $image=''; $ptype=''; //Product type in {type} tag. if (isset($_POST['cmdImport'])) //Save records that were changed. { $filename=$_POST['txtFilename']; //File on user's machine. $s='You are importing '.$filename; crDebug($s); //DEBUG if (move_uploaded_file($_FILES['txtFilename']['tmp_name'], 'upload/')) { $filename=$_FILES['txtFilename']['name']; $s='Received '.$filename; crInfomsg($s); } else { $errmsg='File upload failed. Error is '.$_FILES['txtFilename']['error']; crError($_SERVER['PHP_SELF'].' line '.__LINE__,$errmsg,true); } if (!(file_exists($filename))) { $errmsg='File '.$filename.' does not exist. Cannot continue.'; crError($_SERVER['PHP_SELF'].' line '.__LINE__,$errmsg,true); } else { } } //if isset($_POST['cmdImport'] ?> <!--------------------------------------------------------> <form action="<?php echo $_SERVER['PHP_SELF'].'?'.SID; ?>" method="post"> <hr/> <label for="cbxBrand">Pick one Brand</label> <?php $oldbrandarr=array(); //Init array. //Do query and loop here. //Show brands from zzbrands. $query = "SELECT bzz ". "FROM zzb ". "ORDER BY br ". ";"; //crInfomsg($query); //DEBUG crCreateSelect($query, 'cbxBrand', 'brand') ?> <p>Input file: <input type="file" name="txtFilename" id="txtFilename" value="" size="80" /> <br/><input type="submit" value="Import" name="cmdImport" /> </form> </body> </html> My problem is I get an error each time "File upload failed" which is displayed above when I try to do move_uploaded_file(). I'm not experienced processing text files. Can someone help me or point me to a website? One more thing, the subdir "upload" is located at the same level as this php file. That is where the uploaded files will go temporarily. Hi to all!! I am still new to php.. I need help in reading my text file and inserting it to mysql database. My text file contains 5 fields and has several rows.. The format of my text file: 1 romeo 8877 2010-07-07 abc1 2 nick 7686 2010-07-07 abc2 3 mark 5456 2010-07-07 abc3 4 karm 3432 2010-07-07 abc4 The first field is an INTEGER, the second third fifth fields are VARCHAR and the fourth field is a DATE. I am having trouble with my php code.. My code is this: <?php mysql_connect("localhost","root",""); mysql_select_db("personss"); $textFileName = $_POST['textFileName']; $myFile = "$textFileName"; $fh = fopen($myFile, 'r'); $theData = fread($fh, filesize($myFile)); fclose($fh); $person = explode("\n", $theData); $count = 0; foreach($person as $i => $line) { $nameParts = explode(" ", $person[$count]); $q = "insert into logged (id, name, num, datess, letters) values ('" . implode("','",$nameParts) . "')"; $rw = mysql_query($q) or die("Problem with the query: $q<br>" . mysql_error()); } ?> This code can insert to the database but it only inserts the first row and it loops the insert according to how many rows there are in the text file..For example in my text file there are are 4 rows, it inserts the first row: 1 romeo 8877 2010-07-07 abc1 4times..If there are 6 rows, 6 times the first row will also be inserted.. What i need Sir's is that i need to be able to insert the rows line by line.. if there are 4 rows, i need to insert them all in the database.. Please help me to fix the code. I am looking for a way to upload a csv file to a website and have it populate a database. Does anyone know of a way to do this. The users of the site are novice website users and I am a novice php coder. Any help would be hugely appreciated. Thanks I need to search through a text file and output certain text. My current script doesn't work well at all. Code: [Select] <? $file = 'flist.txt'; $handle = @fopen($file, "r"); $names = array(); $func = array(); $desc = array(); $nme; $fnc; $dsc; $s = -1; $e = -1; $n = 0; if ($handle) { while (($buffer = fgets($handle, 4096)) !== false) { if($nme == 0) { if(strpos($buffer,"<a name") !== false) { $nme = 1; $s = strpos($buffer,"<a name"); } } else if($nme == 1) { if(strpos($buffer,"</span>") !== false) { $nme = 2; $e = strpos($buffer,"</span>"); $num = $e - $s; $names[$n] = strip_tags(substr($buffer,$s,$num)); } } else if($nme == 2) { if($fnc == 0) { if(strpos($buffer,"<table style") !== false) { $fnc = 1; $s = strpos($buffer,"<table style"); } } else if($fnc == 1) { if(strpos($buffer,"</td>") !== false) { $fnc = 2; $e = strpos($buffer,"</td>"); $num = $e - $s; $func[$n] = strip_tags(substr($buffer,$s,$num)); } } else if($fnc == 2) { if($dsc == 0) { if(strpos($buffer,"<p>") !== false) { $dsc = 1; $s = strpos($buffer,"<p>"); } } else if($dsc == 1) { if(strpos($buffer,"</p>") !== false) { $fnc = 0; $nme = 0; $dsc = 0; $e = strpos($buffer,"</p>"); $num = $e - $s; $desc[$n] = strip_tags(substr($buffer,$s,$num)); } } } } } if (!feof($handle)) { echo "Error: unexpected fgets() fail\n"; } fclose($handle); $n = 0; while($n < 100) { echo $names[$n] . "<br>"; echo $func[$n] . "<br>"; echo $desc[$n] . "<p>"; $n ++; } } ?> 4096 gets the data for each line, right? Well some of my data uses two lines. After all the searching is done I need it to output $names, $func, and $desc in plain text. Hi All, sure this is simple but I'm still new to php/mySQL so errors are abundant! I have a simple form with one input: a browse button so the user can find a .csv file on their computer. User then clicks button, upon which I would like the file to be read and the contents put into an array, and the values to be added to the database. I do not need the file to be stored (uploaded). So far my code is not erroring, it just doesn't add the values to the db. I'm wondering if it's just that I HAVE to upload and save the file to the webserver else I can't read it? if(isset($_FILES['file_path']['tmp_name'])&& $_FILES['file_path']['tmp_name'] !=''){ $file_to_import = $_FILES['file_path']['tmp_name']; $import_data = file($file_to_import); print_r($import_data); if ($import_data !=''){ for($index = 1; $index < sizeof($import_data); $index++){ $order_data = explode(",",$import_data[$index]); tep_db_query("UPDATE orders SET act_shipping_cost = '" . $order_data[8]. "' WHERE orders_id = '". $order_data[0]."'"); echo "done it"; } }else{ echo 'error cant read file!'; } } else{ ?> <!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN"> etc etc etc <form id="shipping_costs_upload" name="csv_file_reader" method="post" action="shipping_cost_upload.php"> <div class="main" id="info_text"><h2>Upload Actual Shipping Costs CSV</h2><p>To upload actual shipping cost data, browse to your csv and click the Upload Data button.<br /><br /></p> <div class="date" id="file"> <strong>CSV File: </strong><input type="file" name="file_path" id="file_url" /> </div> <div class="date"><input type="submit" value="Upload Data"> </div> </form> etc etc etc Apologies if I'm being a complete dunce! I'm trying to use the readfile() function to read a html page which has a video embedded (.swf file). When I call the function, it seems like it just loads the html file but without the dependent files (css,js, etc) When I call it directly it loads just fine. Created a hyperlink 'openvideo.php?id=video' that calls this function below: if($_REQUEST['id'] == 'video') { readfile('/usr/home/site.com/htdocs/content/videofolder/video.html'); } else { echo 'nada'; } Any help is appreciated. This is a continuation of my previous post. I would like to be able to read the second column of a tab delimited txt file into a variable as a string. let's say i have: Code: [Select] somegarbage_here readthisinto$file I'm looking for this but all tuts seem to be about importing it to arrays and what not. I just want to import the second column. There is always one line. i have a log file which gets new data time by time. is there any way i can read only new added entries (block) in the file? instead of start reading file from start to the end of file. this file size will be in GBs soon. Thanks. currently i am using file() to read the file. following is the example of new added block in file.
----SMS_START----
recv_time:2014-10-09 18:32:39 Span: 1 From-Number: +1347XXXXXXX Timestamp: 14/10/09 18:32:16 96 Type: PDU SMS-SMSC-Number: +12404492163 Content: Thanks, ----SMS_END---- I very new to php and all I am simply trying to do is read the contents of a text file and echo it out on the screen. I have tried many things to see what I am doing wrong but it just simply isnt working for me. I know the server I am using has php enabled as well because I have tried a simple echo and it works fine. This is the code I am currently using. <?php $file = fopen(file.txt", 'r'); $read = fread($file, '6') echo $read; ?> also, I have tried this. <?php $file = file_get_contents('file.txt'); echo $file; ?> I have a file.txt on the server I am using in the same directory as index.php, I feel like this should be working but I get no result! Alls I have in the text file is a statement that says "hello world". I'm trying to read in a file which is essentially a csv. (I have a couple of books and am a n00b faffing with sessions/cookies etc and am trying to set up an app for a local forum I'm involved with...) I originally tried fgetcsv and also reading the file in line by line (via fgets/explode) and for the most part it works. However some of the entries have a '<' character within them and whenever the script hits a line with one of these it screws up and truncates the line. I presume the '<' is attempting to redirect the data somewhere(?), but have found no way of being able to read this in whole as of yet and I dont really want to resort to processing each line character by character... An example line would be: 3p!<ph4il,Fabulous Diamond Eyes,Lizzies,Div 3C I welcome some advice to put me out of my misery on the matter |