Results 1 to 7 of 7

Thread: file uploading

Threaded View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2003
    Posts
    126

    file uploading

    Can anyone help with the following (details through post):

    Code:
    <form action="p_addphotos.php" method="POST" name="addphoto" ENCTYPE="multipart/form-data">
    
    <table border=0 cellpadding=0 cellspacing=0 width=100%>
    
    <tr>
    <td align=left valign=top><b>Thumbnail:</b></td>
    <td align=left valign=top>
    
    <INPUT TYPE="file" NAME="img1" SIZE="50"></p>
    <INPUT TYPE="hidden" NAME="MAX_FILE_SIZE" VALUE="8000" />
    The size of the thumbnail must be exactly 100 by 100 pixels and must be in the format of *.jpg, *.jpeg or *.gif
    
    </td>
    </tr>
    
    <tr>
    <td align=left valign=top><b>Photo:</b></td>
    <td align=left valign=top>
    
    <INPUT TYPE="file" NAME="img2" SIZE="50"></p>
    The image must be in the format of *.jpg, *.jpeg or *.gif
    
    </td>
    </tr>
    and the code to upload the files

    Code:
    $uploaddir = 'photos/thumbnails/';
    	$uploadfile1 = $uploaddir . $_FILES['img1']['name'];
    
    	$filetypes = array("image/jpg","image/gif","image/jpeg","image/pjpeg");
    	$imageinfo = getimagesize($_FILES['img1']['tmp_name']);
    
    	// upload the file only if the file type is gif or jpg.
    	if(in_array(strtolower($_FILES['img1']['type']),$filetypes) && $imageinfo[0] = 100 && $imageinfo[1] = 100)
    	{
    
    	 // let us read all the files in the directory and rename the file, if exists.
    	 if (file_exists($uploadfile1))
    	 {
    		$path_parts = pathinfo($uploadfile1);
    		$uploadfile1 = $uploaddir.(substr($_FILES['img1']['name'],0,(strlen($_FILES['img1']['name'])-(strlen($path_parts['extension'])+1))).date("YmdHis").".".$path_parts['extension']);
    	 }
    
    	  if (move_uploaded_file($_FILES['img1']['tmp_name'], $uploadfile1))
    	  {
    		$FileSuccess1 = 1;
    	  }
    	  else
    	  {
    		$FileSuccess1 = 0;
    	  }
    	}
    
    	$uploaddir = 'photos/';
    	$uploadfile2 = $uploaddir . $_FILES['img2']['name'];
    
    	$filetypes = array("image/jpg","image/gif","image/jpeg","image/pjpeg");
    
    	// upload the file only if the file type is gif or jpg.
    	if(in_array(strtolower($_FILES['img2']['type']),$filetypes))
    	{
    	 // let us read all the files in the directory and rename the file, if exists.
    	 if (file_exists($uploadfile2))
    	 {
    		$path_parts = pathinfo($uploadfile2);
    		$uploadfile2 = $uploaddir.(substr($_FILES['img2']['name'],0,(strlen($_FILES['img2']['name'])-(strlen($path_parts['extension'])+1))).date("YmdHis").".".$path_parts['extension']);
    	 }
    
    	  if (move_uploaded_file($_FILES['img2']['tmp_name'], $uploadfile2))
    	  {
    		$FileSuccess2 = 1;
    	  }
    	  else
    	  {
    		$FileSuccess2 = 0;
    	  }
    	}
    img1 uploads fine but img2 doesn't go into the if statement:

    Code:
    	if(in_array(strtolower($_FILES['img2']['type']),$filetypes))
    no matter what image extension the file is.

    Can anyone see the reason why? Getting really frustrating
    Last edited by JamesNZ; Jan 6th, 2005 at 03:23 AM.

Posting Permissions

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



Click Here to Expand Forum to Full Width