Jump to content

patsfans

Members
  • Posts

    29
  • Joined

  • Last visited

Everything posted by patsfans

  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?
  16. I just heard from someone else that I need to escape the binary data in the query string; use mysql_real_escape_string(), but I'm not having any luck
  17. Also, the reason why there is a full URL to the image is because this script is one server, while the image is on another. I have a database that has the URL's to all the images in the table, so what I'm trying to do is run the script where it imports the images into a longblob cell and then I'll be deleting the images off the other server. Hopefully this makes sense. - Ian
  18. Not in the sense you are using it. I highly suggest turning it off. Register_globals takes data such as $_GET, $_POST and session and cookies and instead of them being an array they are now $variable. This is bad because most people do not fully understand that if you have a session that contains "loggedin" and if that value is true the user is logged in. Given that without proper checks, anyone can pass $loggedin via Get and be considered logged in. That is the short version, do not turn it on. Leave it off. This has nothing to do with your question. Agreed, and if you absolutely have to use it, place a .htaccess file in the main directory of your domain to enable it so that it's not enabled server wide. If you're on a shared account and don't have control of those settings that's the easiest solution. But use it as a temporary one until you convert your code over.
  19. I looked into this further, but am still having an issue. Here's what I have: <?php $photo = "http://www.example.com/images/picture.jpg"; $image = file_get_contents($photo, FILE_BINARY); $dbname = "database"; $connection = @mysql_connect("localhost", "user", "pass") or die("Couldn't Connect."); $db = @mysql_select_db($dbname, $connection) or die("Couldn't Select Database."); $table = "images"; $sqlcat = " INSERT INTO $table (image) VALUES (\"$image\") "; $resultcat = mysql_query($sqlcat, $connection) or die ("Error in query: $sqlcat. " . mysql_error()); ?> I can't get it to load the image, and then insert it into the LONGBLOB cell. I can't find another example of this online or anything similar, and the file_get_contents reference on php.net obviously doesn't explain this. So thank you for your help so far, and I'm sure this is probably easier than I'm making it out to be.
  20. I tried a basic script a little while ago, but it's returning a broken image: with no value. This came after noticing no blob was going into the database: <? $photo = file_get_contents('http://www.mysite/images/myimage.jpg'); header('Content-type: image/jpeg;'); echo "<IMG SRC=\"$photo\">"; ?> What am I missing? - Ian
  21. That's what I was thinking, but don't the images need to be loaded into a temp folder first before they're inserted? - Ian
  22. I have a site where all the images are currently in a directory on another server (I did it at the time to conserve bandwidth), and am now looking to write a script that will import them from there into a database on a dedicated server as I'm getting rid of the other. Is there a script or code that will load them from that server via the URL, and then insert it into my MYSQL database as a longblob file? I'm just trying to find an efficient way to make the move, and thought that this would be the best way to handle it. Thanks in advance for your help! - Ian
  23. Just bumping this again to see if anyone might know the answer. Does anyone think that changing a setting in the "initialize parser" portion may work or is it in the "set callback functions" that would need to be changed instead? I've tried a few things so far but haven't found a solution yet...very frustrating. Thanks again in advance for your assistance, and hopefully with your help we can mark this "solved" - Ian
  24. Just bumping to see if anyone might know the answer to this. Still haven't quite figured it out yet. The problem seems to be that it's parsing out the text prior to the fields even going into the database, so it seems I need to add some sort of utf command to the parsing script to keep the whole field together before it gets inserted into the database.
  25. Upon further review, it's clearing out the text even before going for the database insert, so it's not getting lost after the fact, whatever it is is happening before the insert even occurs.
×
×
  • 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.