Jump to content

patsfans

Members
  • Posts

    29
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

patsfans's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I'm trying to include the following on a page on a subdomain, which is on the same server as the parent domain: <? include ("/home/httpd/vhosts/mydomain.com/httpdocs/file.php"); ?> Unfortunately the file doesn't open/execute, and the error I get when I check the error log is "Failed opening '/home/httpd/vhosts/mydomain.com/httpdocs/file.php' for inclusion". Again, since it's on a subdomain I'm just wondering if there's a permission issue or if there's something else that needs to be done that I'm just missing?
  2. I'm not sure what gave you that impression. The @ symbol simply suppreses errors. The op needs to wrap there while loop in a check that makes sure that $handle is indeed a resource. if ($handle = fopen($file,"r")) { // while loop in here } Cool - I had a feeling that would do it but didn't realize it required an "if" statement to do it. I'll give that a shot and see if that solves it.
  3. I have a script with the code below that inserts a .csv file into a table, and had an issue where if no file is selected, it throws "fgetcsv() expects parameter 1 to be resource, boolean given" about 1,000,000 times or so until it fills up the error log and the hard drive. I'm guessing someone probably has a simple solution on the below code on how to prevent that going forward, but I've just spent some time looking into it and haven't been able to find the solution. <?php $conn = mysql_connect("localhost", "dbuser", "dbpassword") or die(mysql_error()); mysql_select_db("database") or die(mysql_error()); // Delete existing values in test table before inserting updated file $sql_ini = "TRUNCATE table"; mysql_query($sql_ini) or die(mysql_error()); if(isset($_POST['SUBMIT'])) { $file = $_FILES['file']['tmp_name']; $handle = fopen($file,"r"); while(($fileop = fgetcsv($handle,1000,",")) != false) { $field1 = $fileop[0]; $field2 = $fileop[1]; $field3 = $fileop[2]; // check for default values and delete locked row before inserting data if (!empty($field1)) { // Insert .csv file into database $sql = "INSERT INTO table (field1, field2, field3) values ('$field1', '$field2', '$field3')"; mysql_query($sql) or die(mysql_error()); } } if($sql) { // Show whether or not the file was added successfully: echo "CSV file successfully imported."; } else { echo "Data Insert Failed"; } } } ?> <form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>" enctype="multipart/form-data"> <input type="file" name="file" /> <br> <br> <input type="submit" name="SUBMIT" value="Submit" /> </form> Thank you in advance for your assistance, and I appreciate your help.
  4. Since I'm not overly familiar with AJAX I did some digging since you posted the reply last night and didn't spot anything looked like it would work. As a result I thought I'd check to see if you had any good suggestions looking at the supplied script to potentially point me in the right direction. I appreciate your assistance, and thanks for taking the time to help me out.
  5. Sorry - I realized it would probably be a little more helpful to show you an example of the import script I'm working with: <?php // initialize some variables $currentTag = ""; // this array will hold the values for the SQL statement $values = array(); // this array will hold allowed fields/elements $allowedFields = array("val1", "val2", "val3"); // XML file to parse $xml_file="http://www.mysite.com/xml/Product-Data.xml"; // database parameters $host = "localhost"; $user = "username"; $pass = "pass"; $db = "db"; $table = "table"; // called when parser finds start tag function startElementHandler($parser, $name, $attributes) { global $currentTag; $currentTag = $name; } // called when parser finds end tag function endElementHandler($parser, $name) { global $values, $currentTag; // import database link and table name global $connection, $table; // if ending <item> tag // implies end of record if (strtolower($name) == "tablecorefields") { // NOTE: I dont know what the indices of $values are, // so you might need to do a debug print_r($values) // to find out what they are. $val1 = $values['val1'] ? $values['val1'] : ''; $val2 = $values['val2'] ? $values['val2'] : ''; $val3 = $values['val3'] ? $values['val3'] : ''; // generate the query string $query = "INSERT INTO TABLE "; $query .= "(val1, val2, val3) "; $query .= "VALUES('$val1', '$val2', '$val3');"; // uncomment for debug // print $query; // execute query $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error()); // reset all internal counters and arrays $values = array(); $currentTag = ""; } } // called when parser finds cdata function characterDataHandler($parser, $data) { global $currentTag, $values, $allowedFields; // lowercase tag name $currentTag = strtolower($currentTag); // look for tag in $allowedFields[] array // to see if it is to be included in query if (in_array($currentTag, $allowedFields) && trim($data) != "") { // add field=>value pairs to $values array $values[$currentTag] = mysql_escape_string($data); } } // initialize parser $xml_parser = xml_parser_create(); // turn off whitespace processing xml_parser_set_option($xml_parser,XML_OPTION_SKIP_WHITE, TRUE); // turn on case folding xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, FALSE); // set callback functions xml_set_element_handler($xml_parser, "startElementHandler", "endElementHandler"); xml_set_character_data_handler($xml_parser, "characterDataHandler"); // open connection to database $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); mysql_select_db($db) or die ("Unable to select database!"); // read XML file if (!($fp = fopen($xml_file, "r"))) { die("File I/O error: $xml_file"); } // parse XML while ($data = fread($fp, 4096)) { // error handler if (!xml_parse($xml_parser, $data, feof($fp))) { $error_code = xml_get_error_code($xml_parser); die("XML parser error (error code " . $error_code . "): " . xml_error_string($error_code) . "<br>Error occurred at line " . xml_get_current_line_number($xml_parser)); } } // all done, clean up! xml_parser_free($xml_parser); mysql_close($connection); ?> This works fine to import the .xml data, I'm just trying to make the interface a little cleaner and wanted to get a suggestion on how to show the progress as the import takes place. Thank you in advance
  6. I have a site where I have an admin panel set up to import an XML data feed into a database, but it's a large import and it takes a lot of time to update. I'm looking to upgrade the admin panel and offer the ability to be able to see the number of records as they're being imported instead of it hanging there until the query is completed. The tough part about a progress bar is obviously you have to know the # of items being imported beforehand, and that varies each time the feed is downloaded. So I'm just trying to get some suggestions from someone who may have written something similar. Thanks in advance!
  7. I think I just figured it out: <? $date = "2010-05-19 12:51:47"; //echo date("F n, Y",strtotime($date)); $timestamp = strtotime($date); $formatted_date = date('F d, Y', $timestamp); echo "$formatted_date"; ?> It returned correctly - so hopefully someone else finds this useful.
  8. I have the following code: <? $date = "2010-05-19 12:51:47"; echo date("F n, Y",strtotime($date)); ?> It's outputting May 5, 2010 instead of May 19, 2010. I'm guessing this is easy - so I'm just trying to figure out what I'm doing wrong....?
  9. The answer to this question is here: http://www.phpfreaks.com/forums/index.php/topic,299408.0.html
  10. That is EXACTLY what I needed Thank you!
  11. (I think my post got moved because I didn't explain what I needed properly - so sorry mods if this seems like a duplicate) I need to change a date to a timestamp format using a PHP function. I need to take this: $date = "August 18, 2002"; and then using php convert it to this automatically: $newdate = "2002-08-18 00:00:00"; I've looked here: http://www.php.net/manual/en/function.strptime.php but it shows how to do the reverse of what I need. Does anyone know how the correct PHP function to output it that way?
  12. Everything on that page is terrific - except for the fact that I need to do it in reverse I need to convert: "August 18, 2002" to "2002-08-18 00:00:00"; Everything there shows how to extract numeric dates and reformat them - but I can't find an example of doing it in reverse. I'm guessing it's probably easy - so any help you can provide would be most appreciated
  13. I need to pull the dates for my articles out of my database which are formatted like this: August 18, 2002 and then convert them over to this: $date = "2002-08-18 00:00:00"; I never wrote code to create the timestamp each time the articles were added, but now am in need of making some changes and need to query the dates, and have it insert the timestamp via an UPDATE into the new cell. What's the easiest way to convert the date into a timestamp? Ian
  14. Thanks to cooldude832 who helped me troubleshoot this. I have a friend at the server company and come to find out it was a firewall issue. The added the domain to the firewall white list and it worked perfectly. Thank you to everyone for taking the time to try and help, I appreciate it. And I hope you all have a good weekend! - Ian
  15. Well, it appears I've figured it out (at least the problem anyway). If the URL is not on the local server, it won't load the image (it loaded it via a URL that was to a file on the same domain). Is there a different command I need to use, or a function in .htaccess to tell the server to load remote files?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.