I'm trying to upload a file to an Aruba VPS with CentOS using php.
The php code is as follows:
<?php
session_start();
require 'conexion.php';
use baseDeDatos\conexion as conexion;
$target_file = "pdf/englishtest"."_".date("F")."_".rand(0,1000).substr(basename($_FILES["fileToUpload"]["name"]),-4);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
if($imageFileType == "pdf") {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
$mysqli = conexion\abrirConexion();
$sql = "UPDATE datosapp SET Test='".$target_file."'";
$resultado = $mysqli->query($sql);
header("Location: administrador.php");
} else {
echo "Sorry, there was an error uploading your file.";
}
} else {
echo "Sólo se admiten archivos PDF.";
}
}
?>
This is the php.ini file
;;;;;;;;;;;;;;;;
; File Uploads ;
;;;;;;;;;;;;;;;;
; Whether to allow HTTP file uploads.
; http://www.php.net/manual/en/ini.core.php#ini.file-uploads
file_uploads = On
; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
; http://www.php.net/manual/en/ini.core.php#ini.upload-tmp-dir
;upload_tmp_dir =
; Maximum allowed size for uploaded files.
; http://www.php.net/manual/en/ini.core.php#ini.upload-max-filesize
upload_max_filesize = 2M
and when I run the form to upload PDF's of less than half a Megabyte, what is printed is: "Sorry, there was an error uploading your file.".
When doing Print_r on $ _FILES I get the following:
Array ( [fileToUpload] => Array ( [name] => cv.pdf [type] => application/pdf [tmp_name] => /tmp/phpeudTNd [error] => 0 [size] => 154193 ) )