Jump to content

Problem with image upload/ resize.


will118

Recommended Posts

im new to php coding and i thought i'd finished my website until i came across a problem.

 

when people upload there image it gets shrunk but not resized. i.e a 7mb image just gets shrunk instead of resized so its still full res, just smaller.

 

ive been looking for a script to resize it before uploading, but none fit my needs.

 

its basically an image rating site, the images are some times on the homepage ect.

 

when you upload it registers the image with the mysql db.

 

can you help me instert a script to resize the image on upload.

 

thanks, Will  :D

 

<?
$cntarr=getPics($ses_username);
$totcnt=$cntarr[0]+$cntarr[1];
$maxpics=getSetting("MAXPICTURES");
$thumbheight=getSetting("THUMBHEIGHT");
$thumbwidth=getSetting("THUMBWIDTH");	
$sql="select * from photos where username='$ses_username' and approved='Y'";
$res=mysql_query($sql);
$num=0;
$numcolumns=2;
while($obj=mysql_fetch_object($res))
{
	if($obj->url=="")
	{
		$catarr[$num][0]="<a target='_blank' href='pics/$obj->filename'><img border=0 class=mytable height=$thumbheight width=$thumbwidth src='pics/$obj->filename'></a>";
	}
	else
	{
		$catarr[$num][0]="<a target='_blank' href='$obj->url'><img border=0 class=mytable height=$thumbheight width=$thumbwidth src='$obj->url'></a>";		
	}
	$catarr[$num++][1]="<a href='index.php?cmd=21&id=$obj->photosid'>Delete</a>";
}
for($i=0;(($num%$numcolumns)!=0);$i++)
{
	$catarr[$num][0]=" ";
	$catarr[$num][1]=" ";
	$num++;
}
?>
<script language="JavaScript">
function checkifvalid(){
if ((window.document.myform.url.value=="")&& (window.document.myform.uppic.value==""))
{
alert("please enter the image url or select a picture!");
return false;
}
}
</script>
<table width="100%" border="0" align="left" cellpadding="0" cellspacing="0">
  <tr>
    <td width="7%" height="239" rowspan="3" align="center" valign="top"> <div align="center"><br>
        <br>
        <br>
      </div></td>
    <td width="93%" align="left" valign="top"> 
      <table width="100%" height="100" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td><br>
            <table width="80%" border="0" align="left" cellpadding="0" cellspacing="0" class="mytable">
              <tr> 
                <td valign="top"> <div align="center"> 
                    <table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">

                      <tr > 
                        <td width="1"  class="header"> </td>
                        <td height="20" colspan="2" class="header">My Pictures</td>
                      </tr>
                      <tr > 
                        <td height="25" class="normal"> </td>
                        <td height="25" colspan="2" class="normal">You have <strong> 
                          <? print $cntarr[0];?> </strong> approved pictures and 
                          <strong><? print $cntarr[1];?></strong> pictures awaiting 
                          approval.</td>
                      </tr>
                      <?
			if($cntarr[0]>0)
			{
			for($i=0;$i<$num;$i=$i+$numcolumns)
			{
			?>
                      <tr > 
                        <td height="25" class="normal"> </td>
                        <td width="50%" height="25" align="center" class="normal"><? print $catarr[$i][0]; ?><br> 
                          <? print $catarr[$i][1]; ?></td>
                        <td width="50%" height="19" align="center" class="normal"><? print $catarr[$i+1][0]; ?><br> 
                          <? print $catarr[$i+1][1]; ?></td>
                      </tr>
                      <?
			}
			}
			?>
                    </table>
                  </div></td>
              </tr>
            </table></td>
        </tr>
        <tr>
          <td> </td>
        </tr>
        <tr>
          <td>
	  
<?
  if($totcnt<$maxpics)
  {
  ?>
<table width="80%" height="10" border="0" align="left" cellpadding="0" cellspacing="0" class="mytable">
  <tr> 
    <td valign="top"> <div align="center"> 
                    <table width="100%" height="100%" border="0" align="left" cellpadding="0" cellspacing="0">
                      <form name="myform" action="index.php?cmd=6" method="post" onsubmit="javascript: return checkifvalid();" enctype="multipart/form-data" >
                        <input type="hidden" name="addpic" value="1">
                        <tr > 
                          <td width="1"  class="header"> </td>
                          <td height="20" colspan="2" class="header">Add a Picture</td>
                        </tr>
					<?
					if($uperror!="")
					{
					?>
                        <tr >
					 <td height="25" class="normal"> </td>
                          <td height="25" class="normal" colspan="2"><b><? print $uperror; ?></b></td>
                        </tr>
					<?
					}
					?>
                        <tr > 
                          <td height="25" class="normal"> </td>
                          <td height="25" class="normal">Image URL</td>
                          <td height="19" align="left" class="normal"> <input name="url" type="text" class="mytext" id="url" size="40"></td>
                        </tr>
                        <tr > 
                          <td height="25" class="normal"> </td>
                          <td height="25" colspan="2" class="normal">for eg.http://www.abc.com/abc.gif</td>
                        </tr>
                        <tr > 
                          <td width="1" height="25" class="normal"> </td>
                          <td width="135" height="25" class="normal"><strong>OR</strong> 
                            Select a Picture</td>
                          <td width="281" height="19" align="left" class="normal"> 
                            <input class="mytext" name="uppic" type="file" id="uppic"></td>
                        </tr>
                        <tr align="center" > 
                          <td height="25" colspan="3" class="normal"> <input type="submit" name="Submit" value="Add Picture" class="mybutton"></td>
                        </tr>
                      </form>
                    </table>
      </div></td>
  </tr>
</table>
<?
  }
  ?>

	  </td>
        </tr>
	     <tr>
          <td> </td>
        </tr>
      </table></td>
  </tr>
</table>
<br>

Link to comment
https://forums.phpfreaks.com/topic/48126-problem-with-image-upload-resize/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.