Problema em usar a função file_get_contents() Olá amigos, boa noite! Estou enfrentando um problema em usar a função file_get_contents(). Logo após usá-la o nada pra baixo no código funciona. Alguém já passou por isso? Segue trecho do código: ...
GO
Problema em usar a função file_get_contents()  
Olá amigos, boa noite!

Estou enfrentando um problema em usar a função file_get_contents().
Logo após usá-la o nada pra baixo no código funciona.
Alguém já passou por isso?

Segue trecho do código:

 
  1. <?php
  2. try
  3. {
  4. TTransaction::open('GestaoMedia');
  5. $repository = new TRepository('ArquivosDisponiveis');
  6. $ArquivosDisponiveis = $repository->load();
  7. $slider = './app/resources/slider/index.html';
  8. if (file_exists($slider))
  9. {
  10. new TMessage('info','Arquivo: '.$slider.' existe!');
  11. $slider = file_get_contents("./app/resources/slider/index.html");
  12. // Para na linha acima mas não recebo mensagem de erro.
  13. foreach ($ArquivosDisponiveis as $Arquivo)
  14. {
  15. //Ainda vou terminar a lógica para preencher as cada ocorrência com uma imagem diferente
  16. $slider = str_replace('{IMAGEM}' , $Arquivo->nomeImagem,$slider);
  17. }
  18. TTransaction::close();
  19. }
  20. else
  21. {
  22. new TMessage('info','Arquivo: '.$slider.' não existe!');
  23. }
  24. new TMessage('info','Arquivo final: '.$slider);
  25. }
  26. catch (Exception $e) // in case of exception
  27. {
  28. new TMessage('error', '<b>Error</b> ' . $e->getMessage());
  29. TTransaction::rollback();
  30. }
  31. ?>

Curso Dominando o Adianti Framework

O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado!


Dominando o Adianti Framework Quero me inscrever agora!

Comentários (5)


RB

Geovani, bom dia,

Faltou colocar o Criterio
 
  1. <?php
  2. TTransaction::open('GestaoMedia');
  3. $criteria = new TCriteria; // Acrescenta esta linha aqui
  4. $repository = new TRepository('ArquivosDisponiveis');
  5. $ArquivosDisponiveis = $repository->load($criteria);
  6. ......
  7. ?>
WP

Geovani veja no Log do PHP para ver si não tem algo mais concreto (antes limpe ele caso tiver outras coisas) dai apos isso execute de novo sua APP


Rubens não precisa de criteria para o LOAD do repositorio por Default é NULL (carrega todo o conteudo do Model)
GO

Olá amigos, boa tarde!
O problema foi resolvido. O erro era na linha 20:
 
  1. <?php
  2. $slider = str_replace('{IMAGEM}' , $Arquivo->nomeImagem,$slider);
  3. // O nome do atributo (nomeArquivo) estava errado.
  4. ?>

O código evoluiu e agora eu não estou conseguindo usar uma outra função que seria a str_replace(), ela não estão substituindo a âncora no texto que passo por referência.

Vejam o código:

 
  1. <?php
  2. public function onPreview()
  3. {
  4. try
  5. {
  6. TTransaction::open('GestaoMedia');
  7. $repository = new TRepository('ArquivosDisponiveis');
  8. $ArquivosDisponiveis = $repository->load();
  9. $slider = "";
  10. $linha = "";
  11. $temphtml = "./app/resources/slider/index.html";
  12. if (file_exists($temphtml))
  13. {
  14. foreach ($ArquivosDisponiveis as $umArquivo)
  15. {
  16. //CONCATENAR O NOME DA IMAGEM
  17. $linha = $linha.PHP_EOL.'<img src="'.'./images/'.$umArquivo->nomeArquivo.'" alt="" width="1920" height="1080" />';
  18. }
  19. var_dump($linha);
  20. $src = "./app/resources/slider";
  21. $dst = "tmp/".$umArquivo->id_dispositivo;
  22. $novoArquivo = $dst.'/index.html';
  23. //Copia os arquivos do diretório de referência
  24. $this->rcopy($src,$dst);
  25. // Caso o arquivo index.htm já exista será excluído para atualizar
  26. if (file_exists($novoArquivo)){
  27. $this->rrmdir($novoArquivo);
  28. if (!file_exists($novoArquivo)){
  29. print_r('Conseguiu excluir o arquivo!');
  30. }
  31. else{
  32. print_r('Não Conseguiu excluir o arquivo!');
  33. }
  34. }
  35. //Atualizando o arquivo Index.html
  36. $content = file_get_contents($temphtml);
  37. $content = str_replace('{IMAGENS}', $linha, $content);
  38. $pos = strpos($content,'{IMAGEM}');
  39. if($pos){
  40. print_r('Encontrou a âncora {IMAGEM}!');
  41. }
  42. else {
  43. // sempre entra aqui
  44. print_r('Não encontrou a âncora {IMAGEM}!');
  45. }
  46. file_put_contents($novoArquivo,$content);
  47. if (file_exists($novoArquivo)){
  48. var_dump($novoArquivo);
  49. }
  50. TTransaction::close();
  51. }
  52. else
  53. {
  54. new TMessage('info','Arquivo: '.$slider.' não existe!');
  55. }
  56. new TMessage('info','Arquivo final: '.$slider);
  57. }
  58. catch (Exception $e) // in case of exception
  59. {
  60. new TMessage('error', '<b>Error</b> ' . $e->getMessage());
  61. TTransaction::rollback();
  62. }
  63. }
  64. ?>

Código do arquivo index.htm
<!DOCTYPE html> <!--[if lt IE 7]> <html lang="en" class="no-js ie6"> <![endif]--> <!--[if IE 7]> <html lang="en" class="no-js ie7"> <![endif]--> <!--[if IE 8]> <html lang="en" class="no-js ie8"> <![endif]--> <!--[if gt IE 8]><!--> <html class='no-js' lang='en'> <!--<![endif]--> <head> <meta charset='utf-8' /> <meta content='IE=edge,chrome=1' http-equiv='X-UA-Compatible' /> <title>Exemplo Básico de slider Fullscreen| MaxImage 2.0</title> <meta name="distribution" content="global" /> <meta name="language" content="en" /> <meta content='width=device-width, initial-scale=1.0' name='viewport' /> <meta http-equiv="Cache-Control" content="no-store" /> <link rel="stylesheet" href="./lib/css/jquery.maximage.css" type="text/css" media="screen" charset="utf-8" /> <link rel="stylesheet" href="./lib/css/screen.css" type="text/css" media="screen" charset="utf-8" /> <!--[if lt IE 9]><script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script><![endif]--> <style type="text/css" media="screen"> #maximage { /* position:fixed !important;*/ } /*Set my logo in bottom left*/ #logo { bottom:30px; height:auto; left:30px; position:absolute; width:34%; z-index:1000; } #logo img { width:100%; } </style> <!-- Esse código abaixo foi uma tentadiva de mudar o tempo de duração entre os slides PESQUISAR MAIS SOBRE O ASSUNTO --> <script type="text/javascript"> $(document).ready(function() { $('#conteudo').cycle({ timeout: 1000, //Tempo da transição speed: 400, //Velocidade da transição fx: 'fade', //Tipo pager: '#nav', //A div que vai aprensetar os números do slides prev: '#anterior', //Link para voltar ao slide anterior next: '#proxima' //Link para próximo slide }); }); </script> <!--[if IE 6]> <style type="text/css" media="screen"> /*I don't feel like messing with pngs for this browser... sorry*/ #gradient {display:none;} </style> <![endif]--> </head> <body> <!-- <div id="maximage"> <img src="./images/Rede_show1.jpg" alt="" width="1920" height="1080" /> <img src="./images/Rede_show2.jpg" alt="" width="1920" height="1080" /> <img src="./images/Rede_show3.jpg" alt="" width="1920" height="1080" /> <img src="./images/Rede_show4.jpg" alt="" width="1920" height="1080" /> <img src="./images/Rede_show5.jpg" alt="" width="1920" height="1080" /> <img src="./images/Rede_show6.jpg" alt="" width="1920" height="1080" /> <img src="./images/Rede_show7.jpg" alt="" width="1920" height="1080" /> </div> --> <div id="maximage"> {IMAGENS} </div> <script src='http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.js'></script> <script src="./lib/js/jquery.cycle.all.js" type="text/javascript" charset="utf-8"></script> <script src="./lib/js/jquery.maximage.js" type="text/javascript" charset="utf-8"></script> <script type="text/javascript" charset="utf-8"> $(function(){ // Trigger maximage jQuery('#maximage').maximage(); }); </script> </body> </html>



</html></html></html>
WP

Verifica bem o codigo Geovani

tem lugar que esta {IMAGENS} < com NS ao final e outros apenas {IMAGEM} < com M ao final

Da uma verificada nisso.
GO

Olá Willian Padilha!
Obrigado pelo retorno, já consegui resolver, era esse o problema.