roldahayes Posted November 10, 2007 Share Posted November 10, 2007 Hi please have a look at the code here. I have a csv that has only 2 colums, image url and then a line of text. I'm trying to get the page to read that file but not having much luck!! <?php $quote = file('./files.csv'); foreach($quote as $i => $quote_info) { list($image) = explode(',', $product_info); list($w, $h) = getimagesize($image); } ?> Link to comment https://forums.phpfreaks.com/topic/76747-read-image-and-data-from-csv-file/ Share on other sites More sharing options...
Daukan Posted November 10, 2007 Share Posted November 10, 2007 Hmm try this <?php $quote = file('./files.csv'); foreach($quote as $line_num => $line) { echo '('.$line_num.') '. htmlspecialchars($line) . "<br />\n"; } ?> Link to comment https://forums.phpfreaks.com/topic/76747-read-image-and-data-from-csv-file/#findComment-388563 Share on other sites More sharing options...
roldahayes Posted November 10, 2007 Author Share Posted November 10, 2007 That displays the CSV line but just prints the url of the image instead of loading it with a (0) at the start of the line... Link to comment https://forums.phpfreaks.com/topic/76747-read-image-and-data-from-csv-file/#findComment-388580 Share on other sites More sharing options...
Daukan Posted November 10, 2007 Share Posted November 10, 2007 You said you having trouble getting the page to read the file but it is reading the file according to you. Are you trying to load the image? Link to comment https://forums.phpfreaks.com/topic/76747-read-image-and-data-from-csv-file/#findComment-388597 Share on other sites More sharing options...
roldahayes Posted November 10, 2007 Author Share Posted November 10, 2007 yeah sorry, I the CSV contains a list of famous quotes, and i just want them listed on a page, but next to them at the start i want a "bullet" image to make the page look better so the first colum of the file has ./images/comment.gif then has the quote. heres the page http://www.gkmedia.co.uk/greatoneliners/test.php Hope this makes sense! Link to comment https://forums.phpfreaks.com/topic/76747-read-image-and-data-from-csv-file/#findComment-388603 Share on other sites More sharing options...
Daukan Posted November 10, 2007 Share Posted November 10, 2007 Just use an img tag for the bullet image foreach($quote as $line_num => $line) { echo '<img scr="bullet.png" /> '.htmlspecialchars($line) . "<br />\n"; } Link to comment https://forums.phpfreaks.com/topic/76747-read-image-and-data-from-csv-file/#findComment-388608 Share on other sites More sharing options...
roldahayes Posted November 10, 2007 Author Share Posted November 10, 2007 Ok, it nearly works now! image isn't loading though eben with the direct url as the img scr= http://www.gkmedia.co.uk/greatoneliners/test.php the code i was using earlier is <?PHP $file_handle = fopen("./files/sport.txt", "rb"); while (!feof($file_handle) ) { $line_of_text = fgets($file_handle); $parts = explode('=', $line_of_text); print $parts[0] . $parts[1]. "<BR>"; } fclose($file_handle); ?> can the bullet be added to this as i would prefur using this?? Link to comment https://forums.phpfreaks.com/topic/76747-read-image-and-data-from-csv-file/#findComment-388610 Share on other sites More sharing options...
Daukan Posted November 10, 2007 Share Posted November 10, 2007 <?php $file_handle = fopen("./files/sport.txt", "rb"); while (!feof($file_handle) ) { $line_of_text = fgets($file_handle); $parts = explode('=', $line_of_text); print '<img scr="images/bullet.png />' . $parts[0] . $parts[1]. "<BR>"; } fclose($file_handle); ?> Link to comment https://forums.phpfreaks.com/topic/76747-read-image-and-data-from-csv-file/#findComment-388614 Share on other sites More sharing options...
roldahayes Posted November 10, 2007 Author Share Posted November 10, 2007 Hmmm, still wont load the image... http://www.gkmedia.co.uk/greatoneliners/sport.php Link to comment https://forums.phpfreaks.com/topic/76747-read-image-and-data-from-csv-file/#findComment-388616 Share on other sites More sharing options...
roldahayes Posted November 10, 2007 Author Share Posted November 10, 2007 still can't get it to load the image... Link to comment https://forums.phpfreaks.com/topic/76747-read-image-and-data-from-csv-file/#findComment-388737 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.