1
I have a problem with the PDF insertion code, because the file name is not sent to the database. The code I’m talking about is this:
Form:
<form id="novoEventoForm" action="?page=docs_com&insert=new" enctype="multipart/form-data" method="POST">
PHP:
<?php
$pathToSave = $_SERVER["DOCUMENT_ROOT"] . "psoeiras.pt/documentos/";
/*Checa se a pasta existe - caso negativo ele cria*/
if(!file_exists($pathToSave))
{
mkdir($pathToSave);
}
if( $_FILES )
{ // Verificando se existe o envio de arquivos.
if( $_FILES['new_texto'] )
{ // Verifica se o campo não está vazio.
$dir = $pathToSave; // Diretório que vai receber o arquivo.
$tmpName = $_FILES['new_texto']['tmp_name']; // Recebe o arquivo temporário.
$name = $_FILES['new_texto']['name']; // Recebe o nome do arquivo.
preg_match_all('/\.[a-zA-Z0-9]+/', $name , $extensao);
if(!in_array(strtolower(current(end($extensao))), array('.txt','.pdf', '.doc', '.xls','.xlms')))
{
echo ('Permitido apenas arquivos doc,xls,pdf e txt.');
}
// move_uploaded_file( $arqTemporário, $nomeDoArquivo )
if( move_uploaded_file( $tmpName, $dir . $name ) )
{ // move_uploaded_file irá realizar o envio do arquivo.
echo ('Arquivo adicionado com sucesso. ' );
} else
{
echo ('Erro ao adicionar arquivo.' );
}
}
}
And the form for inserting the PDF is this
<span for="new_texto" style=" display: block; float: left; padding: 10px; margin-top: 10px; padding-top: 8px; height:20px; padding-bottom: 7px; background-color: #111; position: absolute; /* color: beige; */ width: 79px; text-align: center; /* padding-left: 25px; */">Documento</span>
<input type="file" name="new_texto" value="" style="color:black; display: block; border-radius: 0px; outline-color: #0489b1; margin-left: 101px; margin-top: 10px; width: 472px;"/>
Code to Insert PHP
if($_GET['insert'])
{
$new_pagina = strip_tags(trim($_POST['new_pagina']));
$new_etiqueta = strip_tags(trim($_POST['new_etiqueta']));
$new_dia = strip_tags(trim($_POST['new_dia']));
$new_mes = strip_tags(trim($_POST['new_mes']));
$new_ano = strip_tags(trim($_POST['new_ano']));
$new_titulo = strip_tags(trim($_POST['new_titulo']));
$new_texto = strip_tags(trim($_POST['new_texto']));
$new_tipo = strip_tags(trim($_POST['new_tipo']));
$updateSlideshow = mysql_query("INSERT INTO documentos
VALUES('',
'".mysql_real_escape_string($new_pagina)."',
'".mysql_real_escape_string($new_etiqueta)."',
'".mysql_real_escape_string($new_dia)."',
'".mysql_real_escape_string($new_mes)."',
'".mysql_real_escape_string($new_ano)."',
'on',
'".mysql_real_escape_string($new_titulo)."',
'".mysql_real_escape_string($new_texto)."',
'".mysql_real_escape_string($new_tipo)."',
''
) ") or die('1.7231»'.mysql_error());
}
Where is the sending code for the Database?
– Jorge B.
You are not represented here
– Barofscas
But how do you want us to see the problem without that code?
– Jorge B.
I already edited the code above and there’s the part of inserting the content
– Barofscas
You are not using the variable
$name
nowhere.– Jorge B.
So instead of using $name, which use? $new_text??
– Barofscas
Turned out my answer?
– Jorge B.
Yes yes it worked very thank you
– Barofscas
And another question, in the field of my database, I have a div and now I deform the whole site because of this div, which I do?
– Barofscas
Create a new question with this problem.
– Jorge B.
I can’t ask a new question for two days, and I needed help
– Barofscas
Let’s go continue this discussion in chat.
– Jorge B.
Could you continue to help me with that problem I told you about
– Barofscas