Advertisement
Guest User

shalev

a guest
May 19th, 2019
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.32 KB | None | 0 0
  1. <?php
  2. include 'db.php';
  3. $statusMsg = '';
  4.  
  5.  
  6. $targetDir = "uploads/";
  7. $fileName = basename($_FILES["file"]["name"]);
  8. $test = $_POST["test"];
  9. $targetFilePath = $targetDir . $fileName;
  10. $fileType = pathinfo($targetFilePath,PATHINFO_EXTENSION);
  11.  
  12. if(isset($_POST["submit"]) && !empty($_FILES["file"]["name"])){
  13.  
  14.     $allowTypes = array('jpg','png','jpeg','gif','pdf');
  15.     if(in_array($fileType, $allowTypes)){
  16.  
  17.         if(move_uploaded_file($_FILES["file"]["tmp_name"], $targetFilePath)){
  18.  
  19.         $resultt = mysql_query("INSERT INTO images (name, test) VALUES  ('".$fileName."', '".$test."')") or die (mysql_error());
  20.                 $statusMsg = "The file ".$fileName." has been uploaded successfully.";
  21.     }
  22.     }
  23. }
  24.  
  25. echo $statusMsg;
  26.  
  27.     $result = mysql_query("SELECT * FROM `images` ORDER BY `images`.`id` DESC LIMIT 0 , 100") or die(mysql_error());
  28.  
  29.     while($row = mysql_fetch_array($result))
  30.     {  
  31.  
  32. echo <<<html
  33. <img src="uploads/{$row['name']}" alt="" height="100" width="100" />
  34. <br />
  35. {$row['test']}
  36. html;
  37.  
  38.     }
  39.  
  40. echo <<<html
  41. <form action="" method="post" enctype="multipart/form-data">
  42.     בחר תמונה להעלה : <input type="file" name="file">
  43. <br />
  44.     כתוב תוכן לבדיקה : <input type="text" name="test">
  45. <br />
  46.     <input type="submit" name="submit" value="Upload">
  47. </form>
  48. html;
  49.  
  50. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement