vendredi 5 avril 2019

Problem with uploading and viewing pdf files using the website i made

We made a website for a school project that involves uploading a pdf file and viewing them in the website. We tried making the code work on local host before uploading it on a free website hosting site. However, when we tried to test the functionality, the pdf being uploaded does not go to the database, and the files that were initially in the database cannot be viewed, the page only returns characters with diamonds and questions marks.

By the way we used 000webhost as our website host.

Our group has already tried modifying the code for the viewing of the pdf file. We thought it must be some kind of encoding issue, so we tried the solution proposed here in PHP output showing little black diamonds with a question mark. But it still did not solve the problem. For the uploading issue, we still haven't figured out what to change since the code works so well in the localhost.

This is the code we used for uploading the said pdf file into the database:

$fileName = $_FILES['file']['name'];

$fileTmpName  = file_get_contents($_FILES['file']['tmp_name']);

$fileType = $_FILES['file']['type'];
$fileExt = explode('.',$fileName);
  $fileActualExt = strtolower(end($fileExt));
  $allowed = array('pdf');

and this is the code we used for viewing the pdf file:

header('Content-Type:' .$row['password']);

echo $row['data'];

We want to be able to upload pdf files using the website we made, and also view them. Any response from all of you would surely help us. Thank you!




Aucun commentaire:

Enregistrer un commentaire