-2
I’m doing a Backoffice in which I have to insert documents .doc
and .pdf
but I don’t know how to do it, someone can help?
<form name="form" method="post" action="envia_pdf.php" enctype="multipart/form-data">
<label> Selecione o arquivo PDF: </label>
<input type="file" name="pdf" id="pdf" /><br />
<input type="submit" name="envia" value="Enviar" />
</form>
And this code below is the code of the PHP file:
<?php
// Verifica se o campo PDF está vazio
if ($_FILES['pdf']['name'] != "") {
// Caso queira mudar o nome do arquivo basta descomentar a linha abaixo e fazer a modificação
//$_FILES['pdf']['name'] = "nome_do_arquivo.pdf";
// Move o arquivo para uma pasta
move_uploaded_file($_FILES['pdf']['tmp_name'],"documentos/".$_FILES['pdf']['name']);
// $pdf_path é a variável que guarda o endereço em que o PDF foi salvo (para adicionar na base de dados)
$pdf_path = "../documentos/".$_FILES['pdf']['name'];
} else {
// Caso seja falso, retornará o erro
echo "Não foi possível enviar o arquivo";
}
?>
The problem is that when I press the button for the document to be sent, it does not give me any error but only that the document is not sent to the database or to the folder that is referred to in the code.
That’s the problem with this code.
This task can be divided into sub-activities such as, creating the form, uploading/uploading and saving to the database. Decide whether to save the pdf to the bank as a blob(or equivalent) or just its path, to know some of the advantages see: It is wrong to write byte of images in the database?
– rray
The form I have already done, but only that I do not know how to receive/upload and save in the bank and in the folder where all documents will be
– Barofscas
Good, then edit the question and put the form code (select the code and use the button
{ }
to format it.– rray
there is my form, and now I have also a php file in which has some input code
– Barofscas
When asking questions always put the source code if it is too long to leave only relevant part, error messages, do not forget to describe the problem a way to do this is to say what you want to do and what result the system should return and avoid terms like
não funciona
prefer to detail ex: the screen was blank and not enter the record, this helps a lot who will answer. If you tried something, also ask the question, e.g.: I tried to annoy A and got error 000, I followed this link and gave error 1111. Now all that remains is to describe the problem :).– rray
Do you have write permission in this folder? To force the error display, add at the beginning of your php:
ini_set('display_errors', true); error_reporting(E_ALL);
– rray
I do not have permission to write because this does not appear me any message when I do Submit
– Barofscas
Add a bar before documents:
move_uploaded_file($_FILES['pdf']['tmp_name'],"/documentos/".$_FILES['pdf']['name']);
Or set the full path to the uploads folder– rray