Jump to content

Fatal error


dezkit

Recommended Posts

Hey guys, i have this gallery script i am making, but i ran into a problem:

Here is my code:

<?php
session_start();
if(!session_is_registered(myusername)){
header("location:/admin");
}
?>
<body bgcolor="#EEEEEE">
<h2>Upload</h2>(will take a while to upload)
<form enctype="multipart/form-data" action="" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="999999999999999999999999" />
<table border=0>
<tr>
<td>Select File:
<td><input name="file" type="file" /><input type="submit" name="submit" value="Upload File" />
<tr>
</form>
</table><br><br>
<?php

include("config.php");
$submit = $_POST["submit"];
if($submit == "delete"){
foreach($checkbox as $del_id){
  $tbl_name="gallery"; // Table name
  $sql = "DELETE FROM $tbl_name WHERE id='$del_id'";
  $result = mysql_query($sql);
  echo "File has been deleted!<br>";
}
}

if($submit == "Upload File"){
function findexts ($filename)
{
$filename = strtolower($filename) ;
$exts = split("[/\\.]", $filename) ;
$n = count($exts)-1;
$exts = $exts[$n];
return $exts;
}
$ext = findexts ($_FILES['file']['name']) ; 
$ran = rand();
$ran2 = $ran.".";
$sein = "./uploads/";
$target = "./uploads/";
$target = $target . $ran2.$ext; 
$fale = $ran2.$ext;

  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    } else {
    echo "<font color=\"red\" size=\"+1\">Image has been uploaded!</font><br><br>";
   if (file_exists("./uploads/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      } else {
     $filename = $_FILES["file"]["name"];
      move_uploaded_file($_FILES["file"]["tmp_name"], $target);
      $thumbn = $sein . "th-" . $fale;
      cropImage(83, 60, "$target", 'jpg', "$thumbn");
      include("config.php");
      $thumbnailss = "th-".$fale;
      mysql_query("INSERT INTO gallery (thumb_url, full_url) VALUES('$thumbnailss', '$fale' ) ") or die(mysql_error());  
      }
    }

}

$tbl_name="gallery"; // Table name
// select record from mysql
$sql="SELECT * FROM $tbl_name ORDER BY id DESC";
$result=mysql_query($sql);
function cropImage($nw, $nh, $source, $stype, $dest) {
$size = getimagesize($source);
$w = $size[0];
$h = $size[1];
switch($stype) {
	case 'gif':
	$simg = imagecreatefromgif($source);
	break;
	case 'jpg':
	$simg = imagecreatefromjpeg($source);
	break;
	case 'png':
	$simg = imagecreatefrompng($source);
	break;
}
$dimg = imagecreatetruecolor($nw, $nh);
$wm = $w/$nw;
$hm = $h/$nh;
$h_height = $nh/2;
$w_height = $nw/2;
if($w> $h) {
	$adjusted_width = $w / $hm;
	$half_width = $adjusted_width / 2;
	$int_width = $half_width - $w_height;
	imagecopyresampled($dimg,$simg,-$int_width,0,0,0,$adjusted_width,$nh,$w,$h);
} elseif(($w <$h) || ($w == $h)) {
	$adjusted_height = $h / $wm;
	$half_height = $adjusted_height / 2;
	$int_height = $half_height - $h_height;
	imagecopyresampled($dimg,$simg,0,-$int_height,0,0,$nw,$adjusted_height,$w,$h);
} else {
	imagecopyresampled($dimg,$simg,0,0,0,0,$nw,$nh,$w,$h);
}
imagejpeg($dimg,$dest,100);
}
?>
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td><form name="form1" method="post" action="">
<table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td align="center" bgcolor="#FFFFFF"> </td>
<td align="center" bgcolor="#FFFFFF"><strong>Id</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Thumbnail</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Image URL</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"></td>
<td bgcolor="#FFFFFF"><? echo $rows['id']; ?></td>
<td bgcolor="#FFFFFF"><img src="./uploads/<? echo $rows['thumb_url']; ?>"></td>
<td bgcolor="#FFFFFF"><a href="./uploads/<? echo $rows['full_url']; ?>" target="_blank"><? echo $rows['full_url']; ?></a></td>
</tr>
<?

// close while loop
}

?>
</table></td>
</tr>
</table>
<input name="submit" type="submit" id="delete" value="delete"></form>
<?php
// close connection;
mysql_close();
?>

 

Here is the error:

Fatal error: Out of memory (allocated 41680896) (tried to allocate 10368 bytes) in /home/cobi/public_html/admin_gallery.php on line 82

 

Line82: $simg = imagecreatefromjpeg($source);

 

 

EDIT: I FORGOT TO STATE: This error only comes when i upload HUGE files.

Link to comment
Share on other sites

If you're using a shared host, you can't restart the webserver.

 

You might be able to put your own php.ini file into the same directory as the script. In that file put

memory_limit = 64M

 

Or put

<?php
ini_set('memory_limit',0); // no limit
?>

into your script.

 

 

Ken

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.