Advertisement
Guest User

Untitled

a guest
Mar 25th, 2015
468
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // this in home pge script
  2.  
  3. <!doctype>
  4. <html>
  5. <head>
  6. <title>upload test</title>
  7. <script src="button.js"></script>
  8. </head>
  9. <body>
  10. <form action="" method="post" enctype="multipart/form-data">
  11. Select image to upload:
  12. <input id="leftbutton" type="submit" name="upload" value="Upload Foto"/>
  13. <input type="file" id="upload_foto" name="image"style="//display: none;" />
  14. </form>
  15.  
  16. </body>
  17. </html>
  18. <?php
  19. $con=mysqli_connect("localhost","root","","test");
  20. if (mysqli_connect_errno())
  21. {
  22. echo "Failed to connect to MySQL: " . mysqli_connect_error();
  23. }
  24. else{
  25. session_start();
  26. if(!isset($_SESSION["sess_email"])){
  27. header("Location: log.php");
  28. } else {
  29. $useremail=$_SESSION['sess_email'];
  30. $data=mysqli_query($con,"SELECT * FROM login WHERE email='$useremail'") ;
  31. while($row=mysqli_fetch_assoc($data))
  32. {
  33. echo "WECOME ".$dbfirstname=$row['firstname']."<br/>";
  34. echo $dblastname=$row['lastname']."<br/>";
  35. echo $dbuseremail=$row['email']."<br/>";
  36. echo "<br/>";echo "<br/>";echo "<br/>";echo "<br/>";echo "<br/>";
  37. }
  38. }
  39. }
  40. echo "<br/>";echo "<br/>";echo "<br/>";echo "<br/>";echo "<br/>";
  41. $cur = "USERS/";
  42. $gofile=$cur .$_SESSION["sess_email"];
  43.  
  44. // 1.) for print the path
  45. echo $gofile;
  46. echo "<br/>";
  47. //2.) for print the path
  48. $des= dirname($gofile.'/'.$_SESSION["sess_email"]);echo "<br/>";
  49.  
  50. echo $des."<br/>";
  51.  
  52. if(isset($_FILES['image'])){
  53. $errors= array();
  54. $file_name = $_FILES['image']['name'];
  55. $file_size =$_FILES['image']['size'];
  56. $file_tmp =$_FILES['image']['tmp_name'];
  57. $file_type=$_FILES['image']['type'];
  58. $file_ext=strtolower(end(explode('.',$_FILES['image']['name'])));
  59. $extensions = array("jpeg","jpg","png");
  60.  
  61. if(in_array($file_ext,$extensions )=== false){
  62. die("extension not allowed, please choose a JPEG or PNG file.");
  63. }
  64. if($file_size > 1000000){
  65. $errors[]='Big File !';
  66. }
  67. if(empty($errors)==true){
  68. move_uploaded_file($file_tmp,$des.$file_name);
  69. echo "file uploaded";
  70. }else{
  71. print_r($errors);
  72. }
  73. }
  74. // header("Location: home12.php");
  75. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement