Skip to content

Instantly share code, notes, and snippets.

@porfidev
Created May 23, 2015 13:47
Show Gist options
  • Save porfidev/6719e5a08e09a6538a99 to your computer and use it in GitHub Desktop.
Save porfidev/6719e5a08e09a6538a99 to your computer and use it in GitHub Desktop.
Subir archivos y guardarlos con Class Upload
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
<form action="procesarArchivo.php" method="post" enctype="multipart/form-data">
<input type="file" name="imagen" id="imagen"/>
<button type="submit">Cargar Imagen</button>
</form>
</body>
</html>
<?php
/**
* Created by PhpStorm.
* User: elporfirio
* Date: 13/05/15
* Time: 22:17
*/
require_once('UploadHelper/src/class.upload.php');
$imagen = new Upload($_FILES["imagen"]);
$imagen->Process('archivos');
if($imagen->processed){
$ruta = $imagen->file_dst_pathname;
try {
$dbConnection = new PDO(
'mysql:host=' . 'localhost' . ';dbname=' . 'imagenes' .';port=3306',
'homestead',
'secret',
array(
PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8",
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION)
);
} catch (PDOException $ex){
echo "<strong>Error de Conexión: </strong>" . $ex->getMessage() . "<br>";
die();
}
$query = "INSERT INTO pruebas (ruta)
VALUES (:ruta)";
$stmt = $dbConnection->prepare($query);
$stmt->bindParam(':ruta', $ruta);
if($stmt->execute()){
echo "ya se guardo con el ID: " . $dbConnection->lastInsertId();
}
} else {
echo "ocurrio un error:" . $imagen->error;
}
//var_dump($_FILES);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment