-
Notifications
You must be signed in to change notification settings - Fork 0
/
subir_archivo.php
36 lines (31 loc) · 938 Bytes
/
subir_archivo.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
require_once( 'config.php' );
// header('Content-type: text/xml');
if ( $_FILES['imagen']['error'] > 0 )
{
$res = array('error' => true, 'mensaje' => 'El archivo no se ha subido correctamente' );
}
else
{
$nombre = $_FILES['imagen']['name'];
$ext = pathinfo( $nombre, PATHINFO_EXTENSION );
if ( $ext == 'jpg' || $ext == 'png')
{
$dir = pathinfo(__FILE__, PATHINFO_DIRNAME);
$nombre = uniqid() . '.' . $ext;
$rel_name = '/productos/' . $nombre;
$abs_name = $dir . $rel_name;
$base = dirname($_SERVER['REQUEST_URI']);
$move = move_uploaded_file($_FILES['imagen']['tmp_name'],
$abs_name);
$res = array('error' => false,
'mensaje' => 'Archivo subido exitosamente',
'archivo' => $base . $rel_name,
'valor' => $nombre );
} else {
$res = array( 'error' => true,
'mensaje' => 'El archivo seleccionado no es una imagen admitida.');
}
}
echo json_encode( $res );
?>