PHP - Read & Delete Entries In Txt File
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. Similar TutorialsHi guys Im trying to delete multiple images from a page with the code below, I have retirieved the images successfully but i can not delete the with checkbox, wht it does is just refereshing the page and thats it, what im trying to do is to delete the image from the database but it wont. can u help me please? <?php session_start(); include ("../../global.php"); //welcome messaage $username=$_SESSION['username']; echo "$username"; $query=mysql_query("SELECT id FROM users WHERE username='$username'"); while($row = mysql_fetch_assoc($query)) { $user_id = $row['id']; } $ref=$_GET['reference']; $images=mysql_query("SELECT * FROM img WHERE refimage='$ref'"); while($row = mysql_fetch_array($images)) { $image=$row['image']; $thumb=$row['thumb']; ?> <table width="400" border="0" cellspacing="1" cellpadding="0"> <tr> <td><form name="" method="post" action=''> <tr> <td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"></td> <td bgcolor="#FFFFFF"><? echo "<a href='$image' rel='lightbox[roadtrip]'><img src= '$thumb' width='60' height='40' alt='$title'>";?></td> <? } ?> <tr> <td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Delete"></td> </tr> <?php // Check if delete button active, start this $delete = $_REQUEST['delete']; if( $delete != '' ){ $checkbox = $_REQUEST['checkbox']; $count = count($_REQUEST['checkbox']); for($i=0;$i<$count;$i++){ $del_id = $checkbox[$i]; $del = mysql_query("DELETE FROM img WHERE id = '$del_id'"); } } ?> Hi, I want to build into my html table that populates my database table to have a column for checkboxes with a delete button that takes the user to another page to confirm the deletion by outputting a message: Are you sure you want to delete ____, followed by a for loop to see how many checked records to get its ID in order to get its appropriate name. So I have a submit button with name attribute of "delete0" and the values of the input type of checkbox is $row['ID'], for some reason, I get the notice: "Notice: Undefined index: modifyArray in C:\display.php" and modifyArray is the name I give to the checkbox attribute (please see this in my display.php below) Here is my display.php Code: [Select] <table border="border"> <!--NB: checkbox form for multiple delete/update/insert--> <form method="post" action=""> <input type='submit' value='DELETE' name='delete0' /> <?php session_start(); require 'bellSessionDisconnect.inc'; require 'bellConnect.inc.php'; $result=mysql_query("SELECT ID, Image, Name, Manufacturer, Price, Description, SimSupport FROM bellProducts"); //phpinfo(); //NB: print table headings if(mysql_num_rows($result))//if there is at least one entry in bellProducts, make a table { //$counter+=1; print "<table border='border'>"; print "<tr> <th>ID</th> <th>Select entries to modifiy</th> <th>Image</th> <th>Name</th> <th>Manufacturer</th> <th>Price</th> <th>Description</th> <th>SimSupport</th> <th colspan='2' align='center'>Modify</th> </tr>"; //NB: now output each row of records while($row=mysql_fetch_assoc($result)) { //extract($row); "<tr align='center'> <td>$row[ID]</td> <td><input type='checkbox' name='modifyArray[]' value='$row[ID]' /></td> <td>"; if(!empty($row['Image'])) { $curImage=$row['Image']; } else if(empty($row['Image'])) { $curImage='fileUploadIcon.jpg'; //$title="please upload item image"; } print "<img src=$curImage width='70px' height='90px' /> </td> <td> $row[Name] </td> <td> $row[Manufacturer] </td> <td> $$row[Price]</td> <td align='left'>$row[Description]</td> <td>$row[SimSupport]</td> <td><a href='bellUploadForm.php?ID=$row[ID]'>UPLOAD IMAGE</a></td> <td><a href='bellUpdateForm.php?ID=$row[ID]'>UPDATE</a></td> </tr>"; //}//END INNER IF }//END WHILE }//END BIG IF ?> <?php if(array_key_exists('delete0', $_POST)) { $modifyArray=$_POST["modifyArray"]; if(!empty($modifyArray)) { header("Location: http://localhost/bellDeleteForm.php"); exit(); } } ?> </form> </table> I will worry about redirecting to bellDeleteForm.php to confirm the records the user wants to delete after I get this going, please help!!! thanks Maybe some of the great coders here can help this noob out. So here is what I have so far: Code: [Select] //set age criteria for deletion $age = 60; //get current date $datenow = date("Y-m-d"); //set the range we want to delete $delete_range = $datenow - $age; //get old user_id from users table $oldusers_users = mysql_query ("SELECT user_id FROM users WHERE lastvisit < $delete_range "); //get user_id from images table that correspond to users table $oldusers_images = mysql_query ("SELECT user_id FROM images WHERE $oldusers_users=user_id.images "); //find folders that correspond to the usernames and delete $oldusers_files = mysql_query ("SELECT username FROM users WHERE lastvisit < $delete_range "); //print out username //$result = mysql_($oldusers_files); $foldername = mysql_result($oldusers_files, 0); $sigspath = "sigs/"; unlink($sigspath . $foldername . ".gif/index.php"); rmdir($sigspath . $foldername . ".gif"); //now delete user_id's from database mysql_query("DELETE * FROM users WHERE user_id=$oldusers_users"); mysql_query("DELETE * FROM images WHERE user_id=$oldusers_images"); unset($oldusers_users, $oldusers_images, $oldusers_files, $foldername, $sigspath ); mysql_close($link); Right now it is only returning the first entry, not the entire list that meets the criteria. It does delete that one file though but does not remover the rows from the database. I am sure the database stuff is jacked up I am really new to that part. What am I doing wrong here or is there a better way to do this perhaps hello i am a noob and very noob . can anybody help for me as i have been assigned to work with creating newspaper portal and i lied in my CV . so hope you guys understand I'm trying to compare 2 files, each with data separated by ::. I'm trying to make a comparison that if the data to the left of the separator from one file is not found in the same column of the other file, then it is copied to an array. For example: file1.txt abc::def ggg::hhh mmm::ppp file2.txt abc::def zzz::aaa bbb::ccc So... ggg::hhh mmm::ppp is copied from file1.txt because ggg and mmm was not found on the same side in file2.txt ...but I'm not getting any error message with this. The operation just hangs. Code: [Select] <?php $dic1 = file('file1.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); $dic2 = file('file2.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); $titleText = array(); // Storing results into this array. foreach ($dic1 as $dic1line){ list($dic1field1, $dic1field2) = explode('::', $dic1line); foreach ($dic2 as $dic2line){ list($dic2field1, $dic2field2) = explode('::', $dic2line); if ($dic1field1 != $dic2field1) { // Found a non match in DB. array_push($titleText, "$dic1field1 :: $dic1field2\n"); // Store all finds in array. } } } // Finish outputting anything left over. if (empty($titleText)) { // $value was not found -- array is empty. echo 'All matched, or something else.'; } else { $arrayOut = implode("", $titleText); // output the results found in the search. echo $arrayOut; } unset($value); ?> Anyone know how to do this? Thanks. Hi Hope someone can help me please. I have constructed an audio dictionary and have discovered an error now that I have added a few entries to the database. A user can search the database and can click on a result to be taken to the content associated with the entry he chooses. This is the search function; Code: [Select] $search=$_POST["search"]; //get the mysql and store them in $result $result = mysql_query("SELECT word FROM pro_words WHERE word LIKE '%$search%'"); //get the db content that is specified above if (mysql_num_rows($result) < 1) { echo "<br><br><h2> We didn't find anything. Sorry - we did look though.</h2>"; }else { echo '<table align="center" cellspacing="8" cellpadding="8" width="85%"><tr><td align="left"><b>Word</b></td></tr>'; echo "<br><br><h2>Success! Here's what we found:</h2><br>"; while ($r=mysql_fetch_array($result, MYSQLI_ASSOC)) echo '<h2><tr><td align="left"><a href="word.php?w=' . $r['word'] . '">' . $r['word'] . '</a></td></tr></h2>'; } You will see that content is displayed in a new file called word.php. This is relevant code from word.php Code: [Select] $query = "SELECT word,word_type1,sentence1,word_type2,sentence2,word_type3,sentence3 FROM pro_words"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo '<div class="colmask rightmenu">'; echo '<div class="colleft">'; echo '<div class="col1">'; echo '<p>Here are some example sentences that show how we use the word; </p>'; echo '<div id="small"><i> ' . $row['word_type1'] . '</i></div>'; echo '<p><div id="small">' . $row['sentence1'] . '</p></div>'; echo '<div id="small"><i> ' . $row['word_type2'] . '</i></div>'; echo '<p><div id="small">' . $row['sentence2'] . '</p></div>'; echo '<div id="small"><i> ' . $row['word_type3'] . '</i></div>'; echo '<p><div id="small">' . $row['sentence3'] . '</p></div>'; } The problem is that every entry on the database is echoed in word.php whereas I would like only the entries for the word selected to appear. Thanks in advance for any help; do say if you need more info. I 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?
//if any items in order table then display all items in order table $order_sql = "select * from orders"; $order_result = $handle -> query( $order_sql ); if($order_result->num_rows) { echo '<table bgcolor=#FFFF66 ><td>'; while ($order = $order_result -> fetch_assoc()) { $category_sql = "select category from category where category_id = {$order['category_id']}"; $category_result = $handle -> query( $category_sql ); $category_name = $category_result -> fetch_row(); $menu_sql = "select item_name from menu where item_id = {$order['item_id']}"; $menu_result = $handle -> query( $menu_sql ); $menu_name = $menu_result -> fetch_row(); echo $category_name[0] . ': ' . $menu_name[0] . ' ' . $order['size'] . ' ' . $order['type'] . ' ' . $order['amount'] . '<br />'; //insert data into order.txt file for print $file_insert = $category_name[0] . ": " . $menu_name[0] . " " . $order['size'] . " " . $order['type'] . " " . $order['amount'] . "\r\n"; @ $fp = fopen( 'order.txt', 'ab' ); if($fp) { fwrite( $fp, $file_insert, strlen( $file_insert ) ); } else { echo 'could not insert data into order.txt file for print, CLICK ON NEW ORDER'; } fclose($fp); } I have a Windows-style ini file that contains entries as such:
[Timers] Timer(1)=50 Timer(2)=30 Timer(3)=20 The entries represent an array of 3 different timers Apparently parse_ini_file can't deal with the () format. Is there any way to use this format ini file without having to change how arrays are designated? 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> 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!! 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, 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 ? 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 Hi, I want to read image file and write in to word document file using php. Actually i am developing shopping cart site. for that i have created barcode image. i need to take print outs. for example if i click print means same barcode should be generate 64 times in word document. how i do it? i have tried with COM. please check the following code <?php // starting word $word = new COM("word.application") or die("Unable to instantiate Word"); echo "Loaded Word, version {$word->Version}\n"; //bring it to front $word->Visible = 1; //open an empty document $word->Documents->Add(); //do some weird stuff for($i=1;$i<=64;$i++) { $word->Selection->InlineShapes->AddPicture("D:\Program Files\wamp\www\b.jpg ",false, True); } $word->Documents[1]->SaveAs("D:\Program Files\wamp\www\Uselesstest.doc"); //closing word $word->Quit(); //free the object $word = null; ?> It works fine in local. but it is not working in server (it says COM.class is missing). i have checked some forums they said it works with MS based operation system. i have checked with windows only. Please kindly any one help me asap the way for read and write image file in word document. can we do this any other way? we are reading and writing txt files using php the same can we do with image file (read and write in word document) ?? Thanks Prema 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 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. |