Advertisement
Guest User

Untitled

a guest
Jun 12th, 2016
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.43 KB | None | 0 0
  1. if(isset($_POST['upload'])){
  2. $name = $_POST['name'];
  3. $album_id = $_POST['album'];
  4. $file = $_FILES['file']['name'];
  5. $file_type = $_FILES['file']['type'];
  6. $file_size = $_FILES['file']['size'];
  7. $file_tmp = $_FILES['file']['tmp_name'];
  8. $random_name = rand();
  9. if(empty($name) or empty($file)) {
  10. echo "Please Fill all the Fields ! <br /><br />";
  11. } else {
  12. move_uploaded_file$file_tmp, 'uploads/'.$random_name.'.jpg');
  13. mysql_query("INSERT INTO photos VALUE('', '$name', '$album_id', '$random_name.jpg')");
  14. echo "Photo Uploaded !! <br /><br />";
  15. }
  16. }
  17.  
  18. <?
  19. function openDB()
  20. {
  21. global $conn, $username,$host,$password,$db;
  22. $host = "localhost";
  23. $username ="username";
  24. $password= "password";
  25. $db = "databasename";
  26. $conn = mysql_connect($host, $username,$password) or die(mysql_error());
  27. mysql_select_db($db,$conn) or die(mysql_error());
  28. }
  29. function closeDB()
  30. {
  31. global $conn;
  32. mysql_close($conn);
  33. }
  34. ?>
  35.  
  36. <form action="<? echo $_SERVER[PHP_SELF];?>" method="post" enctype="multipart/form-data">
  37. <table>
  38. <tr>
  39. <td align="left"><b>Product Image:</b></td>
  40. <td><input type="file" accept="image/*" name="product_image" size="60">
  41. </td>
  42. </tr>
  43. <tr>
  44. <td align="left"><b>Product File1:</b></td>
  45. <td><input type="file" accept="*/*" name="product_support_file" size="60">
  46. </td>
  47. </tr>
  48. <tr>
  49. <td align="left"><b>Product File2:</b></td>
  50. <td><input type="file" accept="*/*" name="product_support_file2" size="60">
  51. </td>
  52. </tr>
  53. <tr>
  54. <td align="left"><b>Product Price:</b></td>
  55. <td><input type="text" name="product_price" size="60" required></td>
  56. </tr>
  57. <tr>
  58. <td colspan="7" align="right"><input type="submit" name="insert_product" value="Insert Product Now"></td></tr>
  59. </table>
  60. </form>
  61. <?
  62. openDB();
  63. $product_id = $_POST['product_id'];
  64. $product_title = $_POST['product_title'];
  65. $product_cat = $_POST['product_cat'];
  66. $product_type = $_POST['product_type'];
  67. $product_price = $_POST['product_price'];
  68. $product_desc = $_POST['product_desc'];
  69. $product_keywords = $_POST['product_keywords'];
  70. $product_link = $_POST['product_link'];
  71.  
  72. //getting the image from the feild
  73.  
  74. $product_image = $_FILES['product_image']['name'];
  75. $product_image_tmp = $_FILES['product_image']['tmp'];
  76. $product_support_file = $_FILES['product_support_file']['name'];
  77. $product_support_file_tmp = $_FILES['product_support_file']['tmp'];
  78. $product_support_file2 = $_FILES['product_support_file2']['name'];
  79. $product_support_file2_tmp = $_FILES['product_support_file2']['tmp'];
  80.  
  81. if(isset($_POST['insert_product']))
  82. {
  83. //gets the Text Feild Data
  84. $insert_product = "insert into products(product_id,product_cat, product_type, product_title,
  85. product_price, product_desc, product_image, product_support_file, product_support_file2, product_keywords,product_link)
  86. values('','$product_cat','$product_type','$product_title',
  87. '$product_price','$product_desc','$product_image','$product_support_file','$product_support_file2','$product_keywords','$product_link')";
  88.  
  89.  
  90. if(mysql_query($insert_product))
  91. {
  92. //echo "
  93. //Please enter the file path you wish to add your image to:
  94. //<br><input type='text' name='' value=''></input>";
  95. $file_directory ="../yourdirectory";
  96.  
  97. foreach($_FILES as $file_name => $file_array)
  98. {
  99. if(is_uploaded_file($file_array["tmp_name"]))
  100. {
  101. move_uploaded_file($file_array["tmp_name"],"$file_directory/"
  102. .$file_array["name"]) or die ("Could not copy");
  103. }
  104.  
  105. }
  106. echo"<script language='Javascript'>window.open('ConformationUpload.php');</script>";
  107.  
  108. }
  109. else{
  110. echo"Product adding has been unsuccessfull<b>",mysql_error(),"</b>";
  111. }
  112. closeDB();
  113. }
  114. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement