Error Uploading File to Database

Asked

Viewed 204 times

1

I’m trying to upload a file to the database. Only instead of him sending the file to you, he’s sending you his temporary location.

My code is like this:

$arquivo = $_FILES['arquivo'];
$name = $arquivo['name'];
$file_tmp = $arquivo['tmp_name'];
$file_bin = mysqli_real_escape_string(file_get_contents($file_tmp));


$conn = mysqli_connect('localhost', 'root', '', 'files');
$sql = "INSERT INTO malote_arq (arquivo, nome) VALUES('$file_bin', '$name')";

mysqli_query($conn, $sql);

Then when I go to the bank and rescue the contents of the field filing cabinet he shows it: C:wamp mpphpF1F2.tmp

  • Please put the file_get_contents argument

  • Friend worked out of nowhere, I don’t know how....

  • puts the correct code, please. Edit and ask and underneath put the code that worked.

1 answer

2


This is because it is only the temporary file name and not a path(path) for the file. So first you should know where your server stores the temporary files and add the path to that file and add. Something like this

 file_get_contents(/path/folder/temp/nome_do_arquivo);//este é um caminho inventado

If you have no way of knowing the path, save the time file anywhere you know how to pass as argument to file_get_contents

You can find the Directory in php.info() in upload_tmp_dir.

  • Still unsuccessful friend, he keeps sending the same name I quoted above

Browser other questions tagged

You are not signed in. Login or sign up in order to post.