Need Help. Simple PHP Code

Discussion in 'PHP' started by sharingbuzz, Jan 10, 2011.

  1. #1
    sharingbuzz, Jan 10, 2011 IP
  2. kokulusilgi

    kokulusilgi Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    create myimages folder. and save this script "image_upload.php"

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    <style type="text/css">
    <!--
    body,td,th {
    	font-family: Tahoma;
    	font-size: 11px;
    }
    -->
    </style> 
    </head>
    <body>
    <?php
    // your upload path end slash
    $folder = 'myimages/';
    
    if ($_POST['upload']!='')
    {
    foreach ($_POST['title'] as $key => $title)
    {
    	if ($_FILES['file']['error'][$key]==0)
    	{
    		$file = $_FILES['file'];
    		$allowedExtensions = array("jpg","jpeg","gif","png"); 
    		if (!in_array(end(explode(".", strtolower($file['name'][$key]))), $allowedExtensions)) {
           		$results .= $file['name'][$key].' - image extenstion error !';
          	} else {
    			if ($file['size'][$key]>999999){ 
    				$results .= $file['name'][$key].' - image file size bigger than 999kb !';
    			} else {
    				$tmp = preg_replace('/[^a-z0-9._-]/i', '', $file['name'][$key]);
    				$filename = time().strtolower(preg_replace('/\W-/', '', $tmp));
    				move_uploaded_file($file['tmp_name'][$key], $folder.$filename);
    				$results .= '&lt;img src=&quot;http://www.yourimgserver.com/images/'.$filename.'&quot; alt=&quot;'.$title.'&quot; title=&quot;'.$title.'&quot; style=&quot;padding-bottom:10px&quot;/&gt;&lt;br&gt;<br>';
    			}
    		}
    	}
    }
    ?>
    <a href="image_upload.php">Click Here To Upload More Pictures</a>
    <div style="overflow:auto; border:1px solid #EAEAEA; width:800px; padding:2px;">
    <div style="background-color:#F3F3F3; border:none; width:100%; min-height:300px;">
    <?=$results?>
    </div>
    </div>
    
    <?php
    } else {
    $step = intval($_POST['step']);
    if ($step==2) {
    $num = intval($_POST['num']);
    if ($num<1)
    {
    $num = 1;
    }
    ?>
    <form action="" method="post" enctype="multipart/form-data" name="form2">
     <table width="66%" border="0" cellspacing="0" cellpadding="0">
     <?php
     for ($i=1; $i<($num+1); $i++)
     {
     ?>
         <tr>
    		<td colspan="2"><h3>Image Number <?=$i?> </h3></td>
    
    	</tr>
        <tr>
          <td width="250"><strong>Title</strong> (Leave Empty If not required) </td>
          <td width="61%" align="left"><label>
            <input name="title[]" type="text" id="title[]" />
          </label></td>
        </tr>
        <tr>
          <td><strong>Browse</strong></td>
          <td align="left"><label>
            <input name="file[]" type="file" id="file[]" />
            <input name="num" type="hidden" id="num" value="<?=$i?>" />
          </label></td>
        </tr>
        <?php
    	}
    	?>
     <tr align="left">
          <td><label></label></td>
          <td><br />
          <input name="upload" type="submit" id="upload" value="                  Upload                  " /></td>
     </tr>
    </table>
    </form>
    
    <?php
    } else {
    ?>
    <form name="form1" method="post" action="">
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <th align="left" scope="col"><h2>Please Enter Number Pictures You Want To Upload </h2></th>
    
        </tr>
        <tr>
          <th align="left" scope="col"><label>
            <input name="num" type="text" id="num" />
          </label></th>
        </tr>
        <tr>
          <th scope="row"><input name="step" type="hidden" id="step" value="2" /></th>
        </tr>
    
        <tr>
          <th align="left" scope="row"><label>
            <input name="continue" type="submit" id="continue" value="    Continue   " />
          </label></th>
        </tr>
      </table>
    </form>
    <?php
    }
    }
    ?>
    </body>
    </html>
    PHP:
     
    kokulusilgi, Jan 11, 2011 IP
  3. sharingbuzz

    sharingbuzz Member

    Messages:
    332
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    30
    #3
    Thanks Very Much....kokulusilgi

    I am very thankful to you.....:)
     
    sharingbuzz, Jan 11, 2011 IP
  4. mxicoders

    mxicoders Guest

    Messages:
    32
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    if need more help, from php developers plz dont hesitate to contact
    wordpress.com/2011/01/13/introduction-of-the-custome-php-mysql-programming
     
    mxicoders, Jan 13, 2011 IP