Jump to content

lopes_andre

Members
  • Posts

    167
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

lopes_andre's Achievements

Regular Member

Regular Member (3/5)

0

Reputation

  1. Hi, I'm not an expert in CSS, and I having some trouble with a template. The problem is in the scroll down. I can't put them correctly across all the template. I have the full code of the template here. Just copy/paste and will work. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title> stu nicholls | CSS PLaY | cross browser fixed header/footer layout basic method </title> <style type="text/css" media="screen"> #printhead {display:none;} html { height:100%; max-height:100%; padding:0; margin:0; border:0; background:#fff; font-size:80%; font-family: "trebuchet ms", tahoma, verdana, arial, sans-serif; /* hide overflow:hidden from IE5/Mac */ /* \*/ overflow: hidden; /* */ } body {height:100%; max-height:100%; overflow:hidden; padding:0; margin:0; border:0;} #content {display:block; height:100%; max-height:100%; overflow:hidden; padding-left:0px; position:relative; z-index:3; word-wrap:break-word;} #head {position:absolute; margin:0; top:0; right:18px; display:block; width:100%; height:50px; background:#fff; font-size:1em; z-index:5; color:#000; border-bottom:1px solid #000;} #foot {position:absolute; margin:0; bottom:-1px; right:18px; display:block; width:100%; height:25px; background:#fff; color:#000; text-align:right; font-size:2em; z-index:4; border-top:1px solid #000;} .pad1 {display:block; width:18px; height:50px; float:left;} .pad2 {display:block; height:50px;} .pad3 {display:block; height:500px;} #content p {padding:5px;} .bold {font-size:1.2em; font-weight:bold;} .red {color:#c00; margin-left:5px; font-family:"trebuchet ms", "trebuchet", "verdana", sans-serif;} h2 {margin-left:5px;} h3 {margin-left:5px;} </style> </head> <body> <div id="head"> <div class="pad1"></div><h1>Header</h1> </div> <div id="content"> <div class="pad2"></div> <IFRAME name="teste" src="http://www.yahoo.com" width="100%" height="100%" frameborder=0></IFRAME> <!--<div class="pad3"></div>--> </div> <div id="foot">Footer</div> </body> </html> Can some one give me some clues about what can I do to solve this? Best Regards.
  2. Hi, I have used this method for a recent tests that I have made. It uses fgetcsv php function. public function insertLinesToDb($input_csv_file, $db_table) { // Vou assignar o valor do $this->input_csv_file $this->input_csv_file = $input_csv_file; // Vou apontar para a primeira linha $row = 1; // Vou apanhar as linhas com dados if (($handle = fopen($this->input_csv_file, "r")) !== FALSE) { while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { // Para todas as outras linhas que não a primeira if ($row >=2) { $fields = implode("', '", $data); $fields_final = "('" . $fields . "');"; // Vou inserir para a BD. Aqui nesta linha vou ter de chamar um método do model do CodeIgniter!!!!!!!!!!!!!!! echo "INSERT INTO " . $db_table . " (" . $this->obtainHeader() . ") VALUES " . $fields_final; } // Vou passar para a próxima linha $row = $row + 1; } fclose($handle); } return 0; } Feel free to adapt to MySQL and to your framework.
  3. Hi, I'm testing Exceptions in PHP. But I'm not getting this to work. Please see the code. $testar_classe = new geoIpImportCSV('geolitecity', 'http://geolite.maxmind.com/download/geoip/database/GeoLiteCity_CSV/'); // Bloco Try/Catch try { echo $testar_classe->deleteFileFromDisk('GeoLiteCity-Location.csv'); } catch (Exception $e) { echo $e->getMessage; } I'm running the code above passing to the method "deleteFileFromDisk" a parameter with a wrong name to show the Exception. The method that I'm calling have this code: public function deleteFileFromDisk($fileNameToBeDeleted) { // Apagar ficheiro $handle = unlink($fileNameToBeDeleted); // Fazer a verificação de excepções if (!$handle) { // Passou-se algo e o ficheiro n foi apagado. throw new Exception("Nao foi possivel apagar o ficheiro. (this->deleteFileFromDisk) - " . $fileNameToBeDeleted); } // Correu tudo bem, vou sair return TRUE; } What I'm doing wrong? This Exception does not catch wrong filenames passed to the parameter? The result of running the code is this: Warning: unlink(GeoLiteCity-Location.csv): No such file or directory in C:\xampp \htdocs\testes\testecsv4.php on line 295 Give some clues. Best Regards
  4. Hi, I'm a beginner in PHP OOP and I'm with some doubts about the correct way of handling errors in PHP. Look at this function for example: public function deleteFileFromDisk($fileNameToBeDeleted) { $handle = unlink($fileNameToBeDeleted); if (!$handle) { $result = "(this->deleteFileFromDisk) - Error, " . $fileNameToBeDeleted . " not deleted."; } else { $result = "(this->deleteFileFromDisk) - Success, " . $fileNameToBeDeleted . " deleted."; } return $result; } Is this the correct way of doing it, or I can do better than this? Let me add some details of what I'm achieving... I'm running class methods, and I need to control errors in the process. If any call to the object throw an error I need to catch, stop all the process and send an e-mail with the error. Here are the object interactions: $testar_classe = new geoIpImportCSV('geolitecity', 'http://geolite.maxmind.com/download/geoip/database/GeoLiteCity_CSV/'); $testar_classe->downloadAndSaveFile('./', $testar_classe->obtainDownloadFileName()); $testar_classe->uncompressZipFile($testar_classe->obtainDownloadFileName(), '.'); $testar_classe->deleteLine(1, 'GeoLiteCity-Location.csv'); $testar_classe->deleteLine(1, 'GeoLiteCity-Blocks.csv'); $testar_classe->deleteDataFromTable('tabela1'); $testar_classe->deleteDataFromTable('tabela2'); $testar_classe->insertLinesToDb('GeoLiteCity-Location.csv', 'tabela1'); $testar_classe->insertLinesToDb('GeoLiteCity-Blocks.csv', 'tabela2'); $testar_classe->deleteFileFromDisk($testar_classe->obtainDownloadFileName()); $testar_classe->deleteFileFromDisk('GeoLiteCity-Blocks.csv'); $testar_classe->deleteFileFromDisk('GeoLiteCity-Location.csv'); Which is the best way of handle this? Create a new method to take care of the exceptions? There are any examples on how to do this? Best Regards.
  5. It is solved! What made the function blow out was the usage of the "file()" function. Instead of using the file() that put all the content of the file to memory the refactor of the function have used to read the file line by line and put the contents in a temporary file. public function deleteLine($line_no, $csvFileName) { // this function strips a specific line from a file // if a line is stripped, functions returns True else false // // e.g. // deleteLine(1, xyz.csv); // strip first line $tmpFileName = tempnam(".", "csv"); $strip_return=FALSE; $readFD=fopen($csvFileName,'r'); $writeFD=fopen($tmpFileName,'w'); // check for fopen errors. if($line_no==-1) { $skip=$size-1; } else { $skip=$line_no-1; } $line = 0; while (($buffer = fgets($readFD)) !== false) { if($line!=$skip) fputs($writeFD,$buffer); else $strip_return=TRUE; $line++; } // Vou agora fechar o acesso aos ficheiros fclose($readFD); // Ficheiro Original fclose($writeFD); // Ficheiro Temporário // Apagar o csvFileName(Ficheiro Original) unlink($csvFileName); rename($tmpFileName,$csvFileName); return $strip_return; } So, here is the solution to edit large files using PHP.
  6. Hi, thanks for the reply. Infortunately the function blows up because of memory. Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 34 bytes) There are other options? Best Regards,
  7. Hi I have a function that strips out lines from files. I'm handling with large files(more than 100Mb). I have the PHP Memory with 256MB but the function that handles with the strip out of lines blows up with a 100MB CSV File. What the function must do is this: Originally I have the CSV like: Copyright (c) 2007 MaxMind LLC. All Rights Reserved. locId,country,region,city,postalCode,latitude,longitude,metroCode,areaCode 1,"O1","","","",0.0000,0.0000,, 2,"AP","","","",35.0000,105.0000,, 3,"EU","","","",47.0000,8.0000,, 4,"AD","","","",42.5000,1.5000,, 5,"AE","","","",24.0000,54.0000,, 6,"AF","","","",33.0000,65.0000,, 7,"AG","","","",17.0500,-61.8000,, 8,"AI","","","",18.2500,-63.1667,, 9,"AL","","","",41.0000,20.0000,, When I pass the CSV file to this function I got: locId,country,region,city,postalCode,latitude,longitude,metroCode,areaCode 1,"O1","","","",0.0000,0.0000,, 2,"AP","","","",35.0000,105.0000,, 3,"EU","","","",47.0000,8.0000,, 4,"AD","","","",42.5000,1.5000,, 5,"AE","","","",24.0000,54.0000,, 6,"AF","","","",33.0000,65.0000,, 7,"AG","","","",17.0500,-61.8000,, 8,"AI","","","",18.2500,-63.1667,, 9,"AL","","","",41.0000,20.0000,, It only strips out the first line, nothing more. The problem is the performance of this function with large files, it blows up the memory. The function is: public function deleteLine($line_no, $csvFileName) { // this function strips a specific line from a file // if a line is stripped, functions returns True else false // // e.g. // deleteLine(-1, xyz.csv); // strip last line // deleteLine(1, xyz.csv); // strip first line // Assigna o nome do ficheiro $filename = $csvFileName; $strip_return=FALSE; $data=file($filename); $pipe=fopen($filename,'w'); $size=count($data); if($line_no==-1) $skip=$size-1; else $skip=$line_no-1; for($line=0;$line<$size;$line++) if($line!=$skip) fputs($pipe,$data[$line]); else $strip_return=TRUE; return $strip_return; } It is possible to refactor this function to not blow up with the 256MB PHP Memory? Give me some clues. Best Regards,
  8. Hi, I'm giving my first steps with OOP PHP. I need do pass a property in a object call but I can't do it. Here is the code: <?php $testar_classe = new geoIpImportCSV('geolitecity', 'http://geolite.maxmind.com/download/geoip/database/GeoLiteCity_CSV/'); echo $testar_classe->downloadAndSaveFile('./', $testar_classe->obtainDownloadFileName()); echo $testar_classe->uncompressZipFile($testar_classe->toDownloadFileName, './'); //echo $testar_classe->deleteLine(1, 'GeoLiteCity-Location.csv'); //echo $testar_classe->deleteLine(1, 'GeoLiteCity-Blocks.csv'); //echo $testar_classe->insertLinesToDb('GeoLiteCity-Location.csv', 'tabela1'); //echo $testar_classe->insertLinesToDb('GeoLiteCity-Blocks.csv', 'tabela2'); class geoIpImportCSV { // Propriedades Privadas private $input_zip_file; private $url_without_file; private $input_csv_file; private $csvType; private $toSaveDir; // Propriedades Públicas public $toDownloadFileName; function __construct($csvType, $url_without_file) { $this->url_without_file = $url_without_file; $this->csvType = $csvType; } //.. more code here ... /* Este método faz o download e salva o ficheiro em questão no disco. */ public function downloadAndSaveFile($toSaveDir, $toDownloadFilename) { // Vou assignar a $toSaveDir como variavel de classe $this->toSaveDir = $toSaveDir; // Vou saber qual o URL do ficheiro a fazer download $urlFilenameToDownload = $this->url_without_file . $toDownloadFilename; //$urlFilenameToDownload = "http://geolite.maxmind.com/download/geoip/database/GeoIPv6.csv.gz"; // Para efeitos de DEBUG, COMENTAR/APAGAR // Vou fazer o download do ficheiro e gravar p o disco if (isset($urlFilenameToDownload) == true){ $ToDir = $toSaveDir; ## Where the files will be made on your server. $FileContents = implode('', file($urlFilenameToDownload)); $FileNameP = explode('/', $urlFilenameToDownload); $FileName = $FileNameP[count($FileNameP) - 1]; if (($FileContents != '') && (fopen($ToDir . $FileName, 'w') != 0)){ $File = fopen($ToDir . $FileName, 'w'); $Write = fwrite($File, $FileContents); if ($Write != 0){ echo 'The file ' . $ToDir . $FileName . ' was successfully created!'; fclose($File); } else{ echo 'There was an error; the file could not be created.'; } } } } /* Este método descomprime ficheiros zip e coloca-os numa directoria. */ public function uncompressZipFile ($fileNameToUncompress, $extractTo) { // Criar a instancia $zip = new ZipArchive; // Abrir $open_file = $zip->open($fileNameToUncompress); // Extrair para $extract_file_to = $zip->extractTo($extractTo); // Fechar $close_zip = $zip->close(); // Ver se correu tudo bem if(!$close_zip) { die("Error: the uncompress Zip has not have complete correctly."); } else { return "ok"; } } /.. more code here .. } ?> What I'm trying to achieve is to call the property "$toDownloadFileName" in the call to the object "echo $testar_classe->uncompressZipFile($testar_classe->toDownloadFileName, './');" but gives me error. If I call in this way, it works: "echo $testar_classe->uncompressZipFile(/*$testar_classe->toDownloadFileName*/ 'GeoLiteCity_20101201.zip', './');" How can I call the property of the class in the object method? Best Regards,
  9. Hi, I think I have discovered the problem, but it is not working yet. The full method is this: public function obtainDownloadFileName() { // Vou apanhar o conteúdo do html que lista os ficheiros $url = $this->url_without_file; // o $this->url_without_file é p.e. 'http://geolite.maxmind.com/download/geoip/database/GeoLiteCity_CSV/' $input = @file_get_contents($url) or die("Could not access file: $url"); $regexp = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>(.*)<\/a>"; // Agora vou listar os HREF's if(preg_match_all("/$regexp/siU", $input, $matches, PREG_SET_ORDER)) { // Vou passar os HREF's um a um foreach($matches as $match) { // Aqui vou verificar se o link termina em ".zip" if (preg_match("/.zip$/", $match[2])) { // Vou verificar qual o $csvType if ($this->csvType == 'geolitecity') { // Tenho de apanhar todos com a palavra "city" para o array "$match_word" $match_word[$i] = $this->obtainWordWithWordInArray('city', $match[2]); //echo ($match_word[$i]); // P efeitos de DEBUG, apagar. //$teste22 = $match_word[$i]; // P efeitos de DEBUG, apagar. } elseif ($this->csvType == 'geolitecountry') { // Tenho de apanhar todos com a palavra "country" para o array "$match_word" $match_word[$i] = $this->obtainWordWithWordInArray('country', $match[2]); // Retorna o nome do ficheiro a fazer download (A ACABAR, falta verificar parte do nome!!!!!) //$downloadFileName = $match[2]; DESCOMENTAR!!!!!! } } else { // Neste caso não vou fazer nada, deveria mostrar um erro aqui // echo "Other - " . $match[2] . "<br />"; // Para efeitos de Debug } // Adicionar mais 1 ao contador $i++; } // Agora vou ver qual o ficheiro mais recente if ($this->csvType == 'geolitecity') { // Vou buscar a data mais recente da lista de ficheiros //echo ($match_word[$i]); //$mostRecentDate = $this->obtainMostRecentFile($match_word[$i], '12', '8'); //echo $mostRecentDate; // Vou agora } elseif ($this->csvType == 'geolitecountry') { // Este não faz mt sentido passar aqui(já foi achado lá em cima), mas p ficar como o outro $downloadFileName = $match_word[$i]; } else { // Neste caso não vou fazer nada, DEVERIA mostrar um erro. } // Aqui listo //print_r($match_word); // Para efeitos de DEBUG, apagar. } return $downloadFileName; // "GeoLiteCity_20101201.zip" } The problem is in here: // Vou passar os HREF's um a um foreach($matches as $match) { // Aqui vou verificar se o link termina em ".zip" if (preg_match("/.zip$/", $match[2])) { // Vou verificar qual o $csvType if ($this->csvType == 'geolitecity') { // Tenho de apanhar todos com a palavra "city" para o array "$match_word" $match_word[$i] = $this->obtainWordWithWordInArray('city', $match[2]); //echo ($match_word[$i]); // P efeitos de DEBUG, apagar. //$teste22 = $match_word[$i]; // P efeitos de DEBUG, apagar. } elseif ($this->csvType == 'geolitecountry') { // Tenho de apanhar todos com a palavra "country" para o array "$match_word" $match_word[$i] = $this->obtainWordWithWordInArray('country', $match[2]); // Retorna o nome do ficheiro a fazer download (A ACABAR, falta verificar parte do nome!!!!!) //$downloadFileName = $match[2]; DESCOMENTAR!!!!!! } } else { // Neste caso não vou fazer nada, deveria mostrar um erro aqui // echo "Other - " . $match[2] . "<br />"; // Para efeitos de Debug } // Adicionar mais 1 ao contador $i++; } In this foreach() the variable "$match_word[$i]" it is not realy an Array, because I can display it like this "echo ($match_word[$i]);". And this variable is giving me an output like: GeoLiteCity_20090601.zipGeoLiteCity_20090701.zipGeoLiteCity_20090801.zipGeoLiteCity_20090901.zipGeoLiteCity_20091001.zipGeoLiteCity_20091101.zipGeoLiteCity_20091201.zipGeoLiteCity_20100101.zipGeoLiteCity_20100201.zipGeoLiteCity_20100301.zipGeoLiteCity_20100401.zipGeoLiteCity_20100501.zipGeoLiteCity_20100601.zipGeoLiteCity_20100701.zipGeoLiteCity_20100801.zipGeoLiteCity_20100901.zipGeoLiteCity_20101001.zipGeoLiteCity_20101101.zipGeoLiteCity_20101201.zip Instead of this: array ( 5 => 'GeoLiteCity_20090601.zip', 6 => 'GeoLiteCity_20090701.zip', 7 => 'GeoLiteCity_20090801.zip', 8 => 'GeoLiteCity_20090901.zip', 9 => 'GeoLiteCity_20091001.zip', 10 => 'GeoLiteCity_20091101.zip', 11 => 'GeoLiteCity_20091201.zip', 12 => 'GeoLiteCity_20100101.zip', 13 => 'GeoLiteCity_20100201.zip', 14 => 'GeoLiteCity_20100301.zip', 15 => 'GeoLiteCity_20100401.zip', 16 => 'GeoLiteCity_20100501.zip', 17 => 'GeoLiteCity_20100601.zip', 18 => 'GeoLiteCity_20100701.zip', 19 => 'GeoLiteCity_20100801.zip', 20 => 'GeoLiteCity_20100901.zip', 21 => 'GeoLiteCity_20101001.zip', 22 => 'GeoLiteCity_20101101.zip', 23 => 'GeoLiteCity_20101201.zip' ); My question: In this foreach how can I generate an array like this one? Best Regards,
  10. Hi, I'm working in a Class, I have a method that have a foreach and I need to make live a variable outside them(foreach). // Vou passar os HREF's um a um foreach($matches as $match) { // Aqui vou verificar se o link termina em ".zip" if (preg_match("/.zip$/", $match[2])) { // Vou verificar qual o $csvType if ($this->csvType == 'geolitecity') { // Tenho de apanhar todos com a palavra "city" para o array "$match_word" $match_word[$i] = $this->obtainWordWithWordInArray('city', $match[2]); //print_r($match_word[$i]); } elseif ($this->csvType == 'geolitecountry') { // Tenho de apanhar todos com a palavra "country" para o array "$match_word" $match_word[$i] = $this->obtainWordWithWordInArray('country', $match[2]); // Retorna o nome do ficheiro a fazer download (A ACABAR, falta verificar parte do nome!!!!!) //$downloadFileName = $match[2]; DESCOMENTAR!!!!!! } } else { // Neste caso não vou fazer nada, deveria mostrar um erro aqui // echo "Other - " . $match[2] . "<br />"; // Para efeitos de Debug } // Adicionar mais 1 ao contador $i++; } How can I make the variable "$match_word[$i]" live outside this foreach, it is possible to declare a variable as global? How can I do that? Best Regards,
  11. Hi, I have the following situation: Array ( [5] => GeoLiteCity_20090601.zip [6] => GeoLiteCity_20090701.zip [7] => GeoLiteCity_20090801.zip [8] => GeoLiteCity_20090901.zip [9] => GeoLiteCity_20091001.zip [10] => GeoLiteCity_20091101.zip [11] => GeoLiteCity_20091201.zip [12] => GeoLiteCity_20100101.zip [13] => GeoLiteCity_20100201.zip [14] => GeoLiteCity_20100301.zip [15] => GeoLiteCity_20100401.zip [16] => GeoLiteCity_20100501.zip [17] => GeoLiteCity_20100601.zip [18] => GeoLiteCity_20100701.zip [19] => GeoLiteCity_20100801.zip [20] => GeoLiteCity_20100901.zip [21] => GeoLiteCity_20101001.zip [22] => GeoLiteCity_20101101.zip [23] => GeoLiteCity_20101201.zip ) I have this array with filenames, the patern for the name of the file is NAME_DATE.zip I need to get from this array the most recent file(GeoLiteCity_20101201.zip). Which is the best way of doing this task? Give me some clues. Best Regards,
  12. Hi, I need to read files from a web directory. I have tested the "opendir" function but it doesn't work. <?php if ($handle = opendir('http://geolite.maxmind.com/download/geoip/database/GeoLiteCity_CSV')) { echo "Directory handle: $handle\n"; echo "Files:\n"; /* This is the correct way to loop over the directory. */ while (false !== ($file = readdir($handle))) { echo "$file\n"; } /* This is the WRONG way to loop over the directory. */ while ($file = readdir($handle)) { echo "$file\n"; } closedir($handle); } ?> How can I read files from a directory like this? Best Regards,
×
×
  • 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.