-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload.php
More file actions
48 lines (42 loc) · 1.51 KB
/
upload.php
File metadata and controls
48 lines (42 loc) · 1.51 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
45
46
47
48
<?php
if(isset($_FILES['image'])){
$errors= array();
$file_name = $_FILES['image']['name'];
$file_size =$_FILES['image']['size'];
$file_tmp =$_FILES['image']['tmp_name'];
$file_type=$_FILES['image']['type'];
$file_ext=strtolower(end(explode('.',$_FILES['image']['name'])));
$expensions= array("jpeg","jpg","png");
if(in_array($file_ext,$expensions)=== false){
$errors[]="extension not allowed, please choose a JPEG or PNG file.";
}
if($file_size > 1097152){
$errors[]='File size must be excately 2 MB';
}
if(empty($errors)==true){
move_uploaded_file($file_tmp,"images/".$file_name);
$pat= "images/".$file_name;
send($pat,'kalyantest');
}else{
print_r($errors);
}
}
function send($path,$usname){
$conn=mysqli_connect("localhost","nerds","bunchofnerds","pictest");
$des=mysqli_real_escape_string($conn, $_REQUEST["descme"]);
$how="INSERT INTO userprofile (username,userpic,description) VALUES ('$usname','$path','$des')";
$res=mysqli_query($conn,$how);
if($res){
echo "successfully uploaded image\n";
echo "file path $path";
echo "<img src='$path'/>";
}
/* $que="Select userpic from userprofile limit 1";
$res2=mysqli_query($conn,$que);
while(list($userpic) = $res2->fetch_row()){
echo "$userpic";
//echo "<img src='$userpic'/>";
}
*/
}
?>