Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if(isset($_POST['upload'])){
- $name = $_POST['name'];
- $album_id = $_POST['album'];
- $file = $_FILES['file']['name'];
- $file_type = $_FILES['file']['type'];
- $file_size = $_FILES['file']['size'];
- $file_tmp = $_FILES['file']['tmp_name'];
- $random_name = rand();
- if(empty($name) or empty($file)) {
- echo "Please Fill all the Fields ! <br /><br />";
- } else {
- move_uploaded_file$file_tmp, 'uploads/'.$random_name.'.jpg');
- mysql_query("INSERT INTO photos VALUE('', '$name', '$album_id', '$random_name.jpg')");
- echo "Photo Uploaded !! <br /><br />";
- }
- }
- <?
- function openDB()
- {
- global $conn, $username,$host,$password,$db;
- $host = "localhost";
- $username ="username";
- $password= "password";
- $db = "databasename";
- $conn = mysql_connect($host, $username,$password) or die(mysql_error());
- mysql_select_db($db,$conn) or die(mysql_error());
- }
- function closeDB()
- {
- global $conn;
- mysql_close($conn);
- }
- ?>
- <form action="<? echo $_SERVER[PHP_SELF];?>" method="post" enctype="multipart/form-data">
- <table>
- <tr>
- <td align="left"><b>Product Image:</b></td>
- <td><input type="file" accept="image/*" name="product_image" size="60">
- </td>
- </tr>
- <tr>
- <td align="left"><b>Product File1:</b></td>
- <td><input type="file" accept="*/*" name="product_support_file" size="60">
- </td>
- </tr>
- <tr>
- <td align="left"><b>Product File2:</b></td>
- <td><input type="file" accept="*/*" name="product_support_file2" size="60">
- </td>
- </tr>
- <tr>
- <td align="left"><b>Product Price:</b></td>
- <td><input type="text" name="product_price" size="60" required></td>
- </tr>
- <tr>
- <td colspan="7" align="right"><input type="submit" name="insert_product" value="Insert Product Now"></td></tr>
- </table>
- </form>
- <?
- openDB();
- $product_id = $_POST['product_id'];
- $product_title = $_POST['product_title'];
- $product_cat = $_POST['product_cat'];
- $product_type = $_POST['product_type'];
- $product_price = $_POST['product_price'];
- $product_desc = $_POST['product_desc'];
- $product_keywords = $_POST['product_keywords'];
- $product_link = $_POST['product_link'];
- //getting the image from the feild
- $product_image = $_FILES['product_image']['name'];
- $product_image_tmp = $_FILES['product_image']['tmp'];
- $product_support_file = $_FILES['product_support_file']['name'];
- $product_support_file_tmp = $_FILES['product_support_file']['tmp'];
- $product_support_file2 = $_FILES['product_support_file2']['name'];
- $product_support_file2_tmp = $_FILES['product_support_file2']['tmp'];
- if(isset($_POST['insert_product']))
- {
- //gets the Text Feild Data
- $insert_product = "insert into products(product_id,product_cat, product_type, product_title,
- product_price, product_desc, product_image, product_support_file, product_support_file2, product_keywords,product_link)
- values('','$product_cat','$product_type','$product_title',
- '$product_price','$product_desc','$product_image','$product_support_file','$product_support_file2','$product_keywords','$product_link')";
- if(mysql_query($insert_product))
- {
- //echo "
- //Please enter the file path you wish to add your image to:
- //<br><input type='text' name='' value=''></input>";
- $file_directory ="../yourdirectory";
- foreach($_FILES as $file_name => $file_array)
- {
- if(is_uploaded_file($file_array["tmp_name"]))
- {
- move_uploaded_file($file_array["tmp_name"],"$file_directory/"
- .$file_array["name"]) or die ("Could not copy");
- }
- }
- echo"<script language='Javascript'>window.open('ConformationUpload.php');</script>";
- }
- else{
- echo"Product adding has been unsuccessfull<b>",mysql_error(),"</b>";
- }
- closeDB();
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement