-
Content count
29 -
Joined
-
Last visited
Community Reputation
0 ComumAbout Gustavo2503

Contato
-
Site Pessoal
bgninfo.com
Recent Profile Visitors
The recent visitors block is disabled and is not being shown to other users.
-
Gustavo2503 changed their profile photo
-
Gustavo2503 started following Formatar um número, Múltiplos anexos em email, fgets() and and 7 others
-
Estes são alguns pontos do que eu preciso Eu tenho um sistema que em cada registro tem um ou mais anexos. Os nomes destes anexos estão guardados no banco de dados, e os arquivos ficam na pasta anexos/ no servidor. O usuário manda este registro via email e os anexos devem ir juntos. Eu estou usando a função do PHP mail(). Objetivo: Enviar um email com um ou mais anexos Problema: Este código só está enviando um anexo, que é o último anexo que a query pega. OBS.: Eu não entendo de boundary e de anexos por email, eu peguei esse código na internet, mas eu fiz algumas alterações nele, porque no código original só mandava um anexo. $assunto = "Registros"; $boundary = "XYZ-".md5(date("dmYis"))."-ZYX"; // cabeçalho do email $cabecalho = "MIME-Version: 1.0" . PHP_EOL; $cabecalho .= "Content-Type: multipart/mixed; "; $cabecalho .= "boundary=" . $boundary . PHP_EOL; $cabecalho .= "$boundary" . PHP_EOL; $msg = ""; // Anexos $sql = " SELECT A.LOCAL, A.ARQUIVO FROM TB_ANEXOS AS A LEFT JOIN TB_REGISTROS AS R ON (A.ID_REGISTRO = R.ID) WHERE R.ID = $ID "; $resultado = mysqli_query($link, $sql); if ($resultado){ while ($dados = mysqli_fetch_array($resultado, MYSQLI_ASSOC)){ $LOCAL = $dados['LOCAL']; $ARQUIVO_NAME = $dados['ARQUIVO']; $path = 'anexos/'.$LOCAL; $fileType = mime_content_type( $path ); // Pegando o conteúdo do arquivo $fp = fopen( $path, "rb" ); // abre o arquivo enviado $anexo = fread( $fp, filesize( $path ) ); // calcula o tamanho $anexo = chunk_split(base64_encode( $anexo )); // codifica o anexo em base 64 fclose( $fp ); // fecha o arquivo $msg.= "Content-Type: ". $fileType ."; name=\"". $ARQUIVO_NAME . "\"" . PHP_EOL; $msg.= "Content-Transfer-Encoding: base64" . PHP_EOL; $msg.= "Content-Disposition: attachment; filename=\"". $ARQUIVO_NAME . "\"" . PHP_EOL; $msg.= "$anexo" . PHP_EOL; $msg.= "--$boundary" . PHP_EOL; } } $msg.= "--$boundary" . PHP_EOL; $msg.= "Content-Type: text/html; charset='utf-8'" . PHP_EOL; $msg.= " <!doctype html> <html lang='pt-br'> <head> <meta charset='UTF-8'> <meta name='viewport' content='width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0'> <meta http-equiv='X-UA-Compatible' content='ie=edge'> <title>$assunto</title> <style> h2, b, legend { color: #2d2d2d; } </style> </head> <body> <p>CORPO DO EMAIL</p> </body> </html> "; $msg.= "--$boundary" . PHP_EOL; if(mail($para, $assunto, $msg, $cabecalho)) { echo "<p>Email enviado com sucesso</p>"; } else { echo '<p style="color: #f00">Erro!</p>'; }
-
fgets() não funciona em xml versão 4.00, só funciona na versão 3.10 $arquivo = $_FILES['arquivo']["tmp_name"]; $xml = fopen($arquivo, 'r'); while(!feof($xml)){ $linha = fgets($xml); if (!$linha){ $linha = "Erro"; } } echo $linha; Ele retorna "Erro" quando o xml está na versão 4.00. Como arruma isso?
-
Eu estou criando uma classe que cria modais usando React, eu preciso criar um modal dentro de um modal, para isso, eu quero chamar a mesma função dentro dela mesma. O modal é criado, mas o problema é que ele não abre, abre o modal principal (#modal-1), mas não abre o sub modal (#modal-2), veja como ficou meu código: index.html <!DOCTYPE html> <html lang="pt-br"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Modal</title> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet"> <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"> <script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script> <script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script> <script src="https://unpkg.com/babel-standalone@6.15.0/babel.min.js"></script> <script src="js/modal.js" type="text/babel"></script> <link rel="stylesheet" href="css/modal.css"> </head> <body> <div align="center"> <h1>Modal</h1> </div> <button type="button" data-modal="modal-1">Open Modal</button> <div id="modal-content"></div> <script type="text/babel"> const contentSub = [ <h2>Title SubModal 1</h2>, <p>SubModal</p>, <small>Rodapé submodal 1</small> ]; const idSub = "modal-2"; const content = [ <h2>Title 1</h2>, <section> <button type="button" data-modal="modal-2">Open SubModal</button> <Modal id={idSub} content={contentSub}/> </section>, <small>Rodapé 1</small> ]; const id = "modal-1"; ReactDOM.render( <Modal id={id} content={content}/>, document.getElementById('modal-content') ); </script> </body> </html> js/modal.js class Modal extends React.Component{ constructor(props) { super(props); this.id = this.props.id; this.backgroudColorHeader = this.props.backgroudColorHeader === undefined ? 'rgba(103, 117, 240, 1)' : this.props.backgroudColorHeader; this.textColorHeader = this.props.textColorHeader === undefined ? '#fff' : this.props.textColorHeader; this.backgroudColorBody = this.props.backgroudColorBody === undefined ? 'rgba(255, 255, 255, 1)' : this.props.backgroudColorBody; this.textColorBody = this.props.textColorBody === undefined ? '#000' : this.props.textColorBody; this.backgroudColorFooter = this.props.backgroudColorFooter === undefined ? 'rgba(103, 117, 240, 1)' : this.props.backgroudColorFooter; this.textColorFooter = this.props.textColorFooter === undefined ? '#fff' : this.props.textColorFooter; this.borderRadius = this.props.borderRadius === undefined ? '8px' : this.props.borderRadius; this.content = this.props.content === undefined ? [<h2>header content</h2>, <p>body content</p>, <p>footer content</p>] : this.props.content; this.size = this.props.size === undefined ? 3 : this.props.size; } closeModal = () => { $('#'+this.id).removeClass("show"); $('body').removeClass("overflow-hidden"); }; render(){ $(`[data-modal]`).click( function () { var id = $(this).attr("data-modal"); var el = document.getElementById(id); $(el).addClass("show"); $('body').addClass("overflow-hidden"); }); var background, text; background = this.backgroudColorHeader; text = this.textColorHeader; const transparencyBackgroundHeader = background.substring(background.length-2,background.length-1) -.1; const backgroundColorHeader = `${background.substring(0,background.length-2)}${transparencyBackgroundHeader})`; const styleColorHeader = { backgroundColor: backgroundColorHeader, color: text, borderBottom: `1px solid ${background}` }; background = this.backgroudColorBody; text = this.textColorBody; const styleColorBody = { backgroundColor: background, color: text }; background = this.backgroudColorFooter; text = this.textColorFooter; const transparencyBackgroundFooter = background.substring(background.length-2,background.length-1) -.1; const backgroundColorFooter = `${background.substring(0,background.length-2)}${transparencyBackgroundFooter})`; const styleColorFooter = { backgroundColor: backgroundColorFooter, color: text, borderTop: `1px solid ${background}` }; const styleBorderRadius = {borderRadius: this.borderRadius}; const eDivision = ['h', 'b', 'f']; const eContent = this.content; var div = []; for (var i=0;i<eContent.length;i++){ const part = eDivision[i].replace('h', 'header').replace('b', 'body').replace('f', 'footer')+"-modal"; const closeModal = i === 0 ? <span onClick={this.closeModal} className="close-modal"><i className="material-icons">close</i></span> : "" ; var style; if (i===0) style = styleColorHeader; else if (i===1) style = styleColorBody; else style = styleColorFooter; div.push(<div key={i+1} className={part} style={style}> {closeModal} {eContent[i]} </div>); } const eSize = this.size; const s = ['s', 'm-s', 'm', 'm-l', 'l']; const size = s[eSize-1]; const classModal = (size !== "s" && size !== "m-s" && size !== "m" && size !== "m-l" && size !== "l") ? 'modal-modal modal-m' : "modal-modal modal-"+size; return <div id={this.id} className={classModal}> <div className="overflow-modal"> <div className="container-modal" style={styleBorderRadius}> {div} </div> </div> </div>; } }
-
- react.component
- javascript
-
(and 7 more)
Tagged with:
-
Qual função substituir para dar o mesmo resultado?
-
Eu preciso de um link para abrir um arquivo em decodificado em base64, eu fiz o link mas quando eu abro o link ele não aparece nada, o título da página fica "Sem título" e a página fica branca, vazia. E quando eu clico na URL e dou ENTER, ele aparece o meu arquivo normal. O link está assim: <a target="_blank" href="data:application/pdf;base64,MEU_ARQUIVO_BASE64">Arquivo</a> Como arrumar isso?
-
O que há de errado com o meu código jQuery? function atualizaItens45() { $.ajax({ url: 'tb_itens.php', type: 'POST', data: { id: 45, valor: '1800.00' }, beforeSend: function (){ $('.carregando').fadeIn(); document.title = 'carregando...'; }, complete: function (){ $('.carregando').fadeOut(); document.title = 'TÍTULO'; }, success: function (data) { $('#tabela-itens-info-45 tbody').html(data); $('#tabela-itens-edita-45 tbody').html(data); }, error: function (request, status, erro) { alert('Erro! Por favor entre em contato conosco (COD: 1801)'); } }); } atualizaItens45();
- 1 reply
-
- ajax
- javascript
-
(and 1 more)
Tagged with:
-
Como deixar o tempo de expirar o session infinito?
Gustavo2503 replied to Gustavo2503's topic in PHP
e como deixar que o $_SESSION só expire depois de um mês? -
Como deixar o tempo de expirar o session infinito?
-
Formatação HTML para envio de email (com mail() do PHP) não está para o Outlook
Gustavo2503 posted a topic in PHP
Quando eu abro o email no Gmail, vai em formato de HTML, mas no Outlook fica todo zuado, o código está assim: $email_enviar = "Nome <email@exemplo.com>"; $email_para = "Nome <email@exemplo.com>"; $cabecalho = 'MIME-Version: 1.0' . "\r\n"; $cabecalho.= 'Content-type: text/html; charset=UTF-8;' . "\r\n"; $cabecalho.= "Return-Path: $email_enviar \r\n"; $cabecalho.= "From: $email_enviar \r\n"; $cabecalho.= "Reply-To: $email_enviar \r\n"; $assunto = "Assunto"; $menssagem = " <!doctype html> <html lang='pt-br'> <head> <meta charset='UTF-8'> <meta name='viewport' content='width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0'> <meta http-equiv='X-UA-Compatible' content='ie=edge'> <title>Título</title> <style type='text/css'> </head> <body> <div align='center'> <h1>Título</h1> </div> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean eget commodo tortor, eget tincidunt urna. Aliquam odio elit, tristique ac nisl vel, fermentum porta elit. Suspendisse urna magna, maximus et ipsum quis, rutrum tristique sem. Curabitur faucibus nulla malesuada dolor venenatis pharetra. Curabitur ac massa placerat, viverra nibh id, volutpat nibh. Vestibulum leo purus, placerat vel lorem eu, rhoncus lacinia erat. Morbi venenatis fermentum pretium.</p> </body> </html> "; if (mail($email_para, $assunto, $mensagem, $cabecalho)){ echo 'Sucesso'; } else { echo 'Erro'; } -
Deu certo, muito obrigado!!
-
Eu preciso formatar um número com formatação brasileira para dos EUA. Mas está retornando assim: number_format('450.370,50', 2, '.', ',') Está retornando 450.37 Era pra trazer 450,370.50
-
Obrigado, os dois jeitos deram certo