Results 1 to 1 of 1

Thread: Multiple Image Uploader

  1. #1
    Join Date
    Jan 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Multiple Image Uploader

    Hi all,

    Can somebody please help me with this one as I am literally stumped.

    I need a multiple image uploader script with up to 4 images. But sometimes the client might only upload 1, sometimes 2 and so on, maybe 4 on other occasions when he is uploading stock.

    The tricky bit is that when he then goes to edit that stock, he may only want to change say the one image and leave the other 3 as they are.

    Is this possible, and if somebody already has such a script I would be very grateful.

    I have most of the page below if it helps, and as above the insert part is fine, but the update part is proven a pain as I think I can update the images when all the images are updated, but ideally in update all I want to happen is if they update 1 the other 3 stay as they are.

    Code:
    $flag=1; 
    
    $name="";
    $meta="";
    $ref="";
    $desc="";
    $maker="";
    $date="";
    $weight="";
    $height="";
    $depth="";
    $width="";
    $price="";
    $sold="";
    $conf ="";
    $update="";
    $pcats="";
    $subcats="";
    $dt2=date("Y-m-d H:i:s");
    
    if(isset($_GET['stock_Id']))
    {
    	$stock_Id=$_GET['stock_Id'];
    	$q=mysql_query("select * from stock where stock_Id=$stock_Id") or die (mysql_error());	
    	$rows=mysql_fetch_assoc($q);
    	$name=$rows["stock_Name"];
    	$meta=$rows["stock_MetaTitle"];
    	$pcats=$rows["parent_Category"];
    	$subcats=$rows["sub_Category"];
    	$ref=$rows["stock_Ref"];
    	$desc=$rows["stock_Description"];
    	$maker=$rows["stock_Maker"];
    	$date=$rows["stock_Date"];
    	$weight=$rows["stock_Weight"];
    	$height=$rows["stock_Height"];
    	$depth=$rows["stock_Depth"];
    	$width=$rows["stock_Width"];
    	$price=$rows["stock_Price"];
    	$sold=$rows["stock_Sold"];
    	$pic1=$rows["stock_Image"];
        $pic2=$rows["stock_Image2"];
        $pic3=$rows["stock_Image3"];
        $pic4=$rows["stock_Image4"];
    	$active=$rows["stock_Active"];
    	$time=$rows["stock_DateTime"];
    	$flag=0;
    }
    
    if(isset($_POST['btndelete']))
    {
    	$sr=$_POST['srno1'];
    	$flag=$_POST['flag'];
    	if ($flag==0)
    	{		
    	$q23=mysql_query("delete from stock where stock_Id=$sr") or die (mysql_error());
    	$flag=1;
    	}
    	else
    	{		
    	}
    }
    
    if(isset($_POST['btnsubmit']))
    {
    
    $flag=$_POST['flag'];
    if ($flag==0)
    {
    	
    $name=$_POST['txtname'];
    $desc1=$_POST['e1m1'];	
    	
    $meta=$_POST['txtmeta'];
    $sr=$_POST['srno1'];
    $name=$_POST['txtname'];
    $ref=$_POST['Ref'];
    $desc=$_POST['e1m1'];
    $maker=$_POST['Maker'];
    $date=$_POST['Date'];
    $weight=$_POST['Weight'];
    $height=$_POST['Height'];
    $depth=$_POST['Depth'];
    $width=$_POST['Width'];
    $price=$_POST['txtprice'];
    $sold=$_POST['txtsold'];
    $active=$_POST['active'];
    $pcats=$_POST['pcats'];
    $subcats=$_POST['subcats'];
    
    $str_str='';
        $p='';
        $j=0;
        for($i=0;$i<=3;$i++){
        $j++;
        $p=$_REQUEST['p$j'];
        $file=$_FILES['pic']['name'][$i];
        
        if(!empty($file) ){
                  $str_str.=",pic$j='$file'";
         }
         else if(!empty($p))$str_str.=",pic$j='$p'";
         
         $path1="imgdata/stock/".$file;
         copy($_FILES['pic']['tmp_name'][$i], $path1);     
         
        }
    
    $q24=mysql_query("update stock set stock_Name='$name', stock_MetaTitle='$meta', parent_Category='$pcats', sub_Category='$subcats', stock_Image='imgdata/stock/$pic[0]', stock_Image2='imgdata/stock/$pic[1]', stock_Image3='imgdata/stock/$pic[2]', stock_Image4='imgdata/stock/$pic[3]', stock_Ref='$ref', stock_Description='$desc1', stock_Maker='$maker', stock_Date='$date', stock_Weight='$weight', stock_Height='$height', stock_Depth='$depth',stock_Width='$width', stock_Price='$price', stock_Sold='$sold', stock_Active='$active', stock_DateTime='$dt2' where stock_Id=$sr") or die (mysql_error());
    $flag=1;
    $conf="Data Updated Successfully - Click <a href='http://www.accendsandbox.co.uk/adminSallam/admin_categories.php'>here</a> to continue";
    $update="1";
    }
    else
    {
    $name=$_POST['txtname'];
    $ref=$_POST['Ref'];
    $desc=$_POST['e1m1'];
    $maker=$_POST['Maker'];
    $date=$_POST['Date'];
    $weight=$_POST['Weight'];
    $height=$_POST['Height'];
    $depth=$_POST['Depth'];
    $width=$_POST['Width'];
    $price=$_POST['txtprice'];
    $sold=$_POST['txtsold'];	
    $meta=$_POST['txtmeta'];
    $active=$_POST['active'];
    $pcats=$_POST['pcats'];
    $subcats=$_POST['subcats'];
    
    $pic1='';
    for($i=0;$i<4;$i++){
    if(isset($_FILES['pic1']['name'][$i]))$pic1[$i]=$_FILES['pic1']['name'][$i];
    else $pic1[$i]='';
    }
    for($i=0;$i<4;$i++){
    if(isset($_FILES['pic1']['name'][$i]))$path1= "./imgdata/stock/".$_FILES['pic1']['name'][$i];
    //echo $_FILES['pic1']['tmp_name'][$i]." :". $path1;
    if(!empty($_FILES['pic1']['name'][$i])&&isset($_FILES['pic1']['name'][$i]))copy($_FILES['pic1']['tmp_name'][$i], $path1);
    } 
    								
    $q=mysql_query("insert into stock (stock_Name, stock_MetaTitle, parent_Category, sub_Category, stock_Ref, stock_Description, stock_Maker, stock_Date, stock_Weight, stock_Height, stock_Depth, stock_Width, stock_Price, stock_Sold, stock_Image, stock_Image2, stock_Image3, stock_Image4, stock_Active, stock_DateTime) values('$name','$meta','$pcats','$subcats','$ref','$desc','$maker','$date','$weight','$height','$depth','$width','$price','$sold','imgdata/stock/$pic1[0]','imgdata/stock/$pic1[1]','imgdata/stock/$pic1[2]','imgdata/stock/$pic1[3]','$active','$dt2')") or die (mysql_error());	
    $conf="Data Inserted Successfully - Click <a href='http://www.accendsandbox.co.uk/adminSallam/admin_stock.php'>here</a> to continue";
    $update=1;
    }
    }
     
    ?>
    <? if(isset($_GET['stock_Id']))
    { ?>
    <tr>
    <td bgcolor="#A0B050" width="161">
    <div style="font-family:Verdana, Arial, Helvetica, sans-serif; position:relative; font-size:12px; color:#293334; font-weight:bold; position:relative; float:left; left:1px;">Stock Image 1 (Main):</div>
    </td>
    <td bgcolor="#888888">
    <input type="file" name="pic[]" size="50" /> <input type="hidden" name="p1" value="<?php echo $pic1;?>" /> &nbsp;<img src="<?php echo $pic1;?>" height="100px" />
    </td>
    </tr>
    <? } else { ?>
    <tr>
    <td bgcolor="#A0B050" width="161">
    <div style="font-family:Verdana, Arial, Helvetica, sans-serif; position:relative; font-size:12px; color:#293334; font-weight:bold; position:relative; float:left; left:1px;">Stock Image 1 (Main):</div>
    </td>
    <td bgcolor="#888888">
    <input type="file" name="pic1[]" id="pic1[]" size="50" />
    </td>
    </tr>
    <? } ?>
    
    <? if(isset($_GET['stock_Id']))
    { ?>
    <tr>
    <td bgcolor="#A0B050" width="161">
    <div style="font-family:Verdana, Arial, Helvetica, sans-serif; position:relative; font-size:12px; color:#293334; font-weight:bold; position:relative; float:left; left:1px;">Stock Image 2:</div>
    </td>
    <td bgcolor="#888888">
    <input type="file" name="pic[]" size="50" /> <input type="hidden" name="p2" value="<?php echo $pic2;?>" /> &nbsp;<img src="<?php echo $pic2;?>" height="100px" />
    </td>
    </tr>
    <? } else { ?>
    <tr>
    <td bgcolor="#A0B050" width="161">
    <div style="font-family:Verdana, Arial, Helvetica, sans-serif; position:relative; font-size:12px; color:#293334; font-weight:bold; position:relative; float:left; left:1px;">Stock Image 2:</div>
    </td>
    <td bgcolor="#888888">
    <input type="file" name="pic1[]" id="pic1[]" size="50" />
    </td>
    </tr>
    <? } ?>
    <? if(isset($_GET['stock_Id']))
    { ?>
    <tr>
    <td bgcolor="#A0B050" width="161">
    <div style="font-family:Verdana, Arial, Helvetica, sans-serif; position:relative; font-size:12px; color:#293334; font-weight:bold; position:relative; float:left; left:1px;">Stock Image 3:</div>
    </td>
    <td bgcolor="#888888">
    <input type="file" name="pic[]" size="50" /> <input type="hidden" name="p3" value="<?php echo $pic3;?>" /> &nbsp;<img src="<?php echo $pic3;?>" height="100px" />
    </td>
    </tr>
    <? } else { ?>
    <tr>
    <td bgcolor="#A0B050" width="161">
    <div style="font-family:Verdana, Arial, Helvetica, sans-serif; position:relative; font-size:12px; color:#293334; font-weight:bold; position:relative; float:left; left:1px;">Stock Image 3:</div>
    </td>
    <td bgcolor="#888888">
    <input type="file" name="pic1[]" id="pic1[]" size="50" />
    </td>
    </tr>
    <? } ?>
    <? if(isset($_GET['stock_Id']))
    { ?>
    <tr>
    <td bgcolor="#A0B050" width="161">
    <div style="font-family:Verdana, Arial, Helvetica, sans-serif; position:relative; font-size:12px; color:#293334; font-weight:bold; position:relative; float:left; left:1px;">Stock Image 4:</div>
    </td>
    <td bgcolor="#888888">
    <input type="file" name="pic[]" size="50" /> <input type="hidden" name="p4" value="<?php echo $pic4;?>" /> &nbsp;<img src="<?php echo $pic4;?>" height="100px" />
    </td>
    </tr>
    <? } else { ?>
    <tr>
    <td bgcolor="#A0B050" width="161">
    <div style="font-family:Verdana, Arial, Helvetica, sans-serif; position:relative; font-size:12px; color:#293334; font-weight:bold; position:relative; float:left; left:1px;">Stock Image 4:</div>
    </td>
    <td bgcolor="#888888">
    <input type="file" name="pic1[]" id="pic1[]" size="50" />
    </td>
    </tr>
    <? } ?>
    <tr>
    <td bgcolor="#A0B050" width="161">
    <div style="font-family:Verdana, Arial, Helvetica, sans-serif; position:relative; font-size:12px; color:#293334; font-weight:bold; position:relative; float:left; left:1px;">Stock Active:</div>
    </td>
    <td bgcolor="#888888" width="713">
    <select name="active" size="1">
    <?php 
    if($active==1)
    {
    echo "<option value='1' selected>Active</option>";
    echo "<option value='0'>Inactive</option>";							
    }
    else
    {
    echo "<option value='1' >Active</option>";
    echo "<option value='0' selected>Inactive</option>";							
    }
    ?>
    </select>
    </td>
    </tr>
    
    <tr>
    <td bgcolor="#A0B050" width="161"><br></td>
    <td bgcolor="#888888" width="713">
    <table width="75%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td width="10%">
    <input type="submit" name="btnsubmit" value="Submit">
    <input type="submit" name="btndelete" value="Delete" onClick="return check();">
    <input type="hidden" name="srno1" value="<?= $rows["stock_Id"];?>">
    <input type="hidden" name="action" value="Upload">
    </td>
    </tr>
    </table>
    </td>
    </tr>
    </body>
    </html>
    Last edited by multichild; 03-24-2012 at 08:11 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •