Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. function RemoveExt($nomeArquivo){
  2. for ($i=strlen($nomeArquivo)-1;$i>=0;$i--)
  3. if ($nomeArquivo[$i] == "."){
  4. $nomeArquivo = substr($nomeArquivo, 0, $i);
  5. break;
  6. }
  7. return $nomeArquivo;
  8. } //final da função de exclusão da extensão do arquivo
  9. $servername = "localhost";
  10. $username = "root";
  11. $password = "";
  12. $dbname = "nome_tabela";
  13. // Create connection
  14. $conn = new mysqli($servername, $username, $password, $dbname);
  15. // Check connection
  16. if ($conn->connect_error) {
  17. die("Connection failed: " . $conn->connect_error);
  18. }
  19.  
  20. //le a pasta
  21. //chdir( 'upload/' );
  22. //$arquivos = glob("{*.pdf}", GLOB_BRACE);
  23. //foreach($arquivos as $img)
  24. //echo $img;
  25. //final da leitura
  26. //inicio do select
  27. $sql1 = "SELECT * FROM reg GROUP BY cpf ORDER BY idcli";
  28. $result = $conn->query($sql1);
  29. if ($result->num_rows > 0) {
  30. // output data of each row
  31. chdir( 'upload/' );
  32. $arquivos = glob("{*.pdf}", GLOB_BRACE);
  33. while($row = $result->fetch_assoc()) {
  34. foreach($arquivos as $img)
  35. $arqPasta = RemoveExt($img);
  36. $diretorio = "upload/";
  37. $arq_postado = "1";
  38. $cpf = $row["cpf"];
  39. echo $cpf;
  40. if($cpf !== $arqPasta)
  41. $sql = "UPDATE reg SET arquivo = '$diretorio$img', arqPostado = '$arq_postado' WHERE cpf='$arqPasta'";
  42.  
  43. }
  44. }
  45. if ($conn->query($sql) === TRUE) {
  46. echo "Record updated successfully";
  47. } else {
  48. echo "Error updating record: " . $conn->error;
  49. }
  50.  
  51. $conn->close();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement