HEX
Server: Apache
System: Linux clpupre 5.4.0-90-generic #101-Ubuntu SMP Fri Oct 15 20:00:55 UTC 2021 x86_64
User: undanet (1000)
PHP: 7.4.3
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /home/undanet/www//PortalEmpleo/src/Utils/file_uploader.php
<?php

namespace PortalEmpleo\Utils;

use PortalEmpleo\Controller\UtilsController;

require __DIR__ . '/../../vendor/autoload.php';

//$fileOrigen = "Area"; //HAY QUE QUITARLO PARA QUE SEA EL QUE RECIBA POR PARAMETRO, ES PARA TESTING
//$fileDestino = "Area"; //HAY QUE QUITARLO PARA QUE SEA EL QUE RECIBA POR PARAMETRO, ES PARA TESTING

if(!defined('MAX_SIZE')) {
	//const MAX_SIZE = 10485760;
	define('MAX_SIZE', 10485760);
}


if(isset($fileOrigen) && isset($fileDestino))
{
	try
	{
		$fileExtensionsAllowed = ['doc','docx','pdf'];  //accept=".doc,.docx,application/msword,.pdf,application/pdf"
		if(isset($permiteImagenes) && $permiteImagenes==true)
		{
			$fileExtensionsAllowed = ['doc','docx','pdf', 'jpg', 'jpeg', 'png', 'bmp', 'gif', 'zip'];  //accept=".doc,.docx,application/msword,.pdf,application/pdf,.jpg,.jpeg,image/jpg,.png,image/png,.bmp,image/bmp,.gif,image/gif"
		}
		$fileName = $fileOrigen['name'];
		$fileSize = $fileOrigen['size'];
		$fileTmpName  = $fileOrigen['tmp_name'];
		$fileType = $fileOrigen['type'];
		$farray = explode('.',$fileName);
		$fileExtension = strtolower(end($farray));
		
		if (! in_array($fileExtension,$fileExtensionsAllowed)) {
			$error = "Error: This file extension is not allowed. Please upload .doc, .docx y .pdf files";
			$retorno = false;
			return;
		}

		if ($fileSize <= 0) {
			$error = "Error: Forbidden file size";
			$retorno = false;
			return;
		}

		if ($fileSize > MAX_SIZE) {
			$error = "Error: File exceeds maximum size (10MB)";
			$retorno = false;
			return;
		}

		if (!file_exists(dirname($fileDestino))) {
			mkdir(dirname($fileDestino), 0777, true);
		}
	
		//echo 'subir archivo ' . $fileOrigen['tmp_name'] . ' a la carpeta ' . $fileDestino;
		$retorno = move_uploaded_file($fileOrigen['tmp_name'], $fileDestino);

		/*if($retorno == false)
		{
			echo 'retorno false<br>';
		}*/
		/*if($retorno)
		{
			echo 'Archivo subido con éxito:' . $retorno;
		}*/
	}
	catch (Exception $ex)
	{
		$error = $exception->getMessage();
		$retorno = false;
		return;
	}
}

?>