-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload.php
More file actions
44 lines (32 loc) · 1.56 KB
/
upload.php
File metadata and controls
44 lines (32 loc) · 1.56 KB
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
37
38
39
40
41
42
43
44
<?php
//Getting uploaded files
$file = $_FILES['file'];
$fileName = $_FILES['file']["name"];
$fileTmpName = $_FILES['file']["tmp_name"];
$fileSize = $_FILES['file']["size"];
$fileError = $_FILES['file']["error"];
$fileType = $_FILES['file']["type"];
$fileExt = explode('.', $fileName); // separa el nombre y la extension del archivo por el punto (.)
$fileActualExt = strtolower(end($fileExt)); // lowercase la extension ej: .jpg, .gif,
$allowed = array('jpg', 'gif', 'jpeg', 'png', 'pdf','doc', 'csv', 'css', 'html', 'htm', 'js', 'json', 'php', 'txt', 'xml', 'mp3', 'mp4', 'mpeg'); // array de extensiones permitidas
// define las extensiones permitidas.
if (in_array($fileActualExt, $allowed)) {
if ($fileError === 0) { // si no encuentra errores
if ($fileSize < 1000000){ // define el tamaño del archivo
$fileNameNew = uniqid ('',true).".".$fileActualExt; // Añade un Id al archivo
$fileDestination = 'uploads/'.$fileNameNew; // Define la carpeta donde se guarda el archivo
move_uploaded_file($file ["tmp_name"],"./uploads/".$file["name"]); // Mueve el archivo desde la carpeta temporal al root
header('Location:'. $_SERVER['HTTP_REFERER']);
} else {
echo "Your file is too large";
}
} else {
echo "There was an error uploading the file";
}
} else {
echo "You cannot upload the file of this type";
}
//Uploading in ./uploads folder
// move_uploaded_file($file ["tmp_name"],"./uploads/".$file["name"]);
//Redirecting back
// header('Location:'. $_SERVER['HTTP_REFERER']);