forked from BrunoCostaPrado/Chance
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload.php
40 lines (36 loc) · 1.51 KB
/
upload.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
37
38
39
40
<?php
if(isset($_POST['enviar']) && isset($_FILES['my_image'])){
include 'conectarDB.php';
echo"<pre>";
print_r($_FILES['my_image']);
echo"</pre>";
$img_name = $_FILES['my_image']['name'];
$img_size = $_FILES['my_image']['size'];
$tmp_name = $_FILES['my_image']['tmp_name'];
$error = $_FILES['my_image']['error'];
if($error === 0){
if($img_size > 125000000){
$em = "arquivo grande demais";
header("Location:perfil-maquiagem.php?error=$em");
}else{
$img_ex = pathinfo($img_name,PATHINFO_EXTENSION);
$img_ex_lc = strtolower($img_ex);
$allowed_exs = array("jpg","jpeg","png","gif");
if(in_array($img_ex_lc,$allowed_exs)){
$new_img_name = uniqid("IMG-",true).'.'.$img_ex_lc ;
$img_upload_path = 'uploads/'.$new_img_name;
move_uploaded_file($tmp_name,$img_upload_path);
$sql = "INSERT INTO imagens(img_url)VALUES('$new_img_name')";
mysqli_query($conexao,$sql);
header("Location:perfil-maquiagem.php");
}else{
$em = "tipo de arquivo nao reconhecido";
header("Location:perfil-maquiagem.php?error=$em");
}
}
}else{
$em = "ocorreu um erro desconhecido";
header("Location:perfil-maquiagem.php?error=$em");
}
}
?>