candycanes Posted July 30, 2010 Share Posted July 30, 2010 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! Link to comment https://forums.phpfreaks.com/topic/209325-browse-to-file-and-read-contents/ Share on other sites More sharing options...
trq Posted July 30, 2010 Share Posted July 30, 2010 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? of course you need to upload it first. Reading files on a client would be a massive security hole. Link to comment https://forums.phpfreaks.com/topic/209325-browse-to-file-and-read-contents/#findComment-1093025 Share on other sites More sharing options...
candycanes Posted July 30, 2010 Author Share Posted July 30, 2010 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? of course you need to upload it first. Reading files on a client would be a massive security hole. In that case, what exactly is wrong in my code? As I thought $_FILES['file_path']['tmp_name'] was the file's temporary position on the server, and I would be able to read this file? Link to comment https://forums.phpfreaks.com/topic/209325-browse-to-file-and-read-contents/#findComment-1093028 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.