Jump to content

Error: Need Urgent Help!


dezkit

Recommended Posts

I have this code:

<?php
session_start();
if(!session_is_registered(us)){
header("location:/admin");
}
include("config.php");
$tbl_name="gallery"; // Table name
// select record from mysql
$sql="SELECT * FROM $tbl_name";
$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="500" border="0" cellspacing="1" cellpadding="0">
<tr>
<td><table width="500%" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td bgcolor="#FFFFFF"> </td>
<td colspan="4" bgcolor="#FFFFFF"><strong></strong> </td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFFF"><strong>Id</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Thumbnail</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>URL</strong></td>
<td align="center" bgcolor="#FFFFFF"> </td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td bgcolor="#FFFFFF"><? echo $rows['id']; ?></td>
<td bgcolor="#FFFFFF"><img src="<? echo $rows['thumb_url']; ?>"></td>
<td bgcolor="#FFFFFF" align="center"><a href="<? echo $rows['full_url']; ?>"><? echo $rows['full_url']; ?></a></td>
<td bgcolor="#FFFFFF"><a href="delete_ac.php?id=<? echo $rows['id']; ?>">delete</a></td>
</tr>
<?

// close while loop
}

// close connection;
mysql_close();

?>
</table></td>
</tr>
</table>
<br><br><br><br>
<?php 
$submit = $_POST["submit"];
if($submit == "Upload File"){
if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/png")) || ($_FILES["file"]["type"] == "image/jpg") && ($_FILES["file"]["size"] < 20000000000))
  {
  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>";
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<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"],
      "uploads/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "uploads/" . $_FILES["file"]["name"];
            cropImage(83, 60, '/uploads/$filename', 'jpg', '/uploads/th-$filename');
      }
    }
  }
else
  {
  echo "Invalid file";
  }
}
?>
<br><br><br><br><h2>Upload</h2>
<form enctype="multipart/form-data" action="" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
<table border=0>
<tr>
<td>Select File:
<td><input name="file" type="file" />
<tr>
<td><input type="submit" name="submit" value="Upload File" />
<td><input type="reset" name="reset" value="Reset Field" />
</form>
</table>

 

When I run it, it displays the following errors:

Warning: getimagesize(/uploads/$filename) [function.getimagesize]: failed to open stream: No such file or directory in /home/cobi/public_html/admin_gallery.php on line 12

 

Warning: imagecreatefromjpeg(/uploads/$filename) [function.imagecreatefromjpeg]: failed to open stream: No such file or directory in /home/cobi/public_html/admin_gallery.php on line 20

 

Warning: Division by zero in /home/cobi/public_html/admin_gallery.php on line 37

 

Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home/cobi/public_html/admin_gallery.php on line 40

 

Warning: imagejpeg() [function.imagejpeg]: Unable to open '/uploads/th-$filename' for writing: No such file or directory in /home/cobi/public_html/admin_gallery.php on line 44

 

How do i fix this? Thanks so much guys.

 

Link to comment
Share on other sites

Hey again!

I got this code, but it isn't doing what i want to do.

<?php
session_start();
if(!session_is_registered(myusername)){
header("location:/admin");
}
include("config.php");
$tbl_name="gallery"; // Table name
// select record from mysql
$sql="SELECT * FROM $tbl_name";
$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="500" border="0" cellspacing="1" cellpadding="0">
<tr>
<td><table width="500%" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td bgcolor="#FFFFFF"> </td>
<td colspan="4" bgcolor="#FFFFFF"><strong></strong> </td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFFF"><strong>Id</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Thumbnail</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>URL</strong></td>
<td align="center" bgcolor="#FFFFFF"> </td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td bgcolor="#FFFFFF"><? echo $rows['id']; ?></td>
<td bgcolor="#FFFFFF"><img src="<? echo $rows['thumb_url']; ?>"></td>
<td bgcolor="#FFFFFF" align="center"><a href="<? echo $rows['full_url']; ?>"><? echo $rows['full_url']; ?></a></td>
<td bgcolor="#FFFFFF"><a href="delete_ac.php?id=<? echo $rows['id']; ?>">delete</a></td>
</tr>
<?

// close while loop
}

// close connection;
mysql_close();

?>
</table></td>
</tr>
</table>
<br><br><br><br>
<?php 
$submit = $_POST["submit"];
if($submit == "Upload File"){
if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/png")) || ($_FILES["file"]["type"] == "image/jpg") && ($_FILES["file"]["size"] < 20000000000))
  {
  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>";
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<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"],
      "uploads/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "uploads/" . $_FILES["file"]["name"];
      cropImage(83, 60, "/uploads/$filename", 'jpg', "/uploads/th-$filename");
      mysql_query("INSERT INTO gallery (id, thumb_url, full_url) VALUES('th-$filename', '$filename' ) ") or die(mysql_error());  

      }
    }
  }
else
  {
  echo "Invalid file";
  }
}
?>
<br><br><br><br><h2>Upload</h2>
<form enctype="multipart/form-data" action="" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
<table border=0>
<tr>
<td>Select File:
<td><input name="file" type="file" />
<tr>
<td><input type="submit" name="submit" value="Upload File" />
<td><input type="reset" name="reset" value="Reset Field" />
</form>
</table>

 

Basicly it doesn't insert anything to the mysql table.

Link to comment
Share on other sites

mysql_query("INSERT INTO gallery (id, thumb_url, full_url) VALUES('th-$filename', '$filename' ) ") or die(mysql_error());  

 

There you don't have anything set to insert into id, if you're talking about the auto incrementing id in the database you don't need to include that.

 

Also you might want to set the thumbnail to a variable before putting into the database.

$thumbnail = "th-".$filename;
mysql_query("INSERT INTO gallery (thumb_url, full_url) VALUES('$thumbnail', '$filename' ) ") or die(mysql_error());  

Link to comment
Share on other sites

Now i am getting these errors:

Warning: getimagesize(/uploads/haydog.jpg) [function.getimagesize]: failed to open stream: No such file or directory in /home/cobi/public_html/admin_gallery.php on line 12

Warning: imagecreatefromjpeg(/uploads/haydog.jpg) [function.imagecreatefromjpeg]: failed to open stream: No such file or directory in /home/cobi/public_html/admin_gallery.php on line 20

Warning: Division by zero in /home/cobi/public_html/admin_gallery.php on line 37

Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home/cobi/public_html/admin_gallery.php on line 40

Warning: imagejpeg() [function.imagejpeg]: Unable to open '/uploads/th-haydog.jpg' for writing: No such file or directory in /home/cobi/public_html/admin_gallery.php on line 44

 

 

Here is my current code:

<?php
session_start();
if(!session_is_registered(myusername)){
header("location:/admin");
}
include("config.php");
$tbl_name="gallery"; // Table name
// select record from mysql
$sql="SELECT * FROM $tbl_name";
$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="500" border="0" cellspacing="1" cellpadding="0">
<tr>
<td><table width="500%" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td bgcolor="#FFFFFF"> </td>
<td colspan="4" bgcolor="#FFFFFF"><strong></strong> </td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFFF"><strong>Id</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Thumbnail</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>URL</strong></td>
<td align="center" bgcolor="#FFFFFF"> </td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td bgcolor="#FFFFFF"><? echo $rows['id']; ?></td>
<td bgcolor="#FFFFFF"><img src="<? echo $rows['thumb_url']; ?>"></td>
<td bgcolor="#FFFFFF" align="center"><a href="<? echo $rows['full_url']; ?>"><? echo $rows['full_url']; ?></a></td>
<td bgcolor="#FFFFFF"><a href="delete_ac.php?id=<? echo $rows['id']; ?>">delete</a></td>
</tr>
<?

// close while loop
}

// close connection;
mysql_close();

?>
</table></td>
</tr>
</table>
<br><br><br><br>
<?php 
$submit = $_POST["submit"];
if($submit == "Upload File"){
if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/png")) || ($_FILES["file"]["type"] == "image/jpg") && ($_FILES["file"]["size"] < 20000000000))
  {
  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>";
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<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"],
      "uploads/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "uploads/" . $_FILES["file"]["name"];
      cropImage(83, 60, "/uploads/$filename", 'jpg', "/uploads/th-$filename");
      include("config.php");
      $thumbnailss = "th-".$filename;
      mysql_query("INSERT INTO gallery (thumb_url, full_url) VALUES('$thumbnailss', '$filename' ) ") or die(mysql_error());  
      }
    }
  }
else
  {
  echo "Invalid file";
  }
}
?>
<br><br><br><br><h2>Upload</h2>
<form enctype="multipart/form-data" action="" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
<table border=0>
<tr>
<td>Select File:
<td><input name="file" type="file" />
<tr>
<td><input type="submit" name="submit" value="Upload File" />
<td><input type="reset" name="reset" value="Reset Field" />
</form>
</table>

 

Also: Can somebody fix my broken code, I love you guys <3

Link to comment
Share on other sites

Nevermind, I fixed it myself. Oh and guys. I need some sort of more help :D

 

I now have this code(I know):

<?php
session_start();
if(!session_is_registered(myusername)){
header("location:/admin");
}
include("config.php");
$tbl_name="gallery"; // Table name
// select record from mysql
$sql="SELECT * FROM $tbl_name";
$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="500" border="0" cellspacing="1" cellpadding="0">
<tr>
<td><table width="500%" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td bgcolor="#FFFFFF"> </td>
<td colspan="4" bgcolor="#FFFFFF"><strong></strong> </td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFFF"><strong>Id</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>Thumbnail</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong>URL</strong></td>
<td align="center" bgcolor="#FFFFFF"> </td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td bgcolor="#FFFFFF"><? echo $rows['id']; ?></td>
<td bgcolor="#FFFFFF"><img src="./uploads/<? echo $rows['thumb_url']; ?>"></td>
<td bgcolor="#FFFFFF" align="center"><a href="./uploads/<? echo $rows['full_url']; ?>"><? echo $rows['full_url']; ?></a></td>
<td bgcolor="#FFFFFF"><a href="delete_ac.php?id=<? echo $rows['id']; ?>">delete</a></td>
</tr>
<?

// close while loop
}

// close connection;
mysql_close();

?>
</table></td>
</tr>
</table>
<br><br><br><br>
<?php 
$submit = $_POST["submit"];
if($submit == "Upload File"){
if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/png")) || ($_FILES["file"]["type"] == "image/jpg") && ($_FILES["file"]["size"] < 20000000000))
  {
  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>";
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<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"],
      "uploads/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "./uploads/" . $_FILES["file"]["name"];
      cropImage(83, 60, "./uploads/$filename", 'jpg', "./uploads/th-$filename");
      include("config.php");
      $thumbnailss = "th-".$filename;
      mysql_query("INSERT INTO gallery (thumb_url, full_url) VALUES('$thumbnailss', '$filename' ) ") or die(mysql_error());  
      }
    }
  }
else
  {
  echo "Invalid file";
  }
}
?>
<br><br><br><br><h2>Upload</h2>
<form enctype="multipart/form-data" action="" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
<table border=0>
<tr>
<td>Select File:
<td><input name="file" type="file" />
<tr>
<td><input type="submit" name="submit" value="Upload File" />
<td><input type="reset" name="reset" value="Reset Field" />
</form>
</table>

 

How come when i upload an image, i have to reload the page in order to see it on the UPLOADED FILES column?

Link to comment
Share on other sites

So how do I make to insert after selecting it? I'm completely confused on doing that.

Edit: When i upload a png image it says:

Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: gd-jpeg: JPEG library reports unrecoverable error: in /home/cobi/public_html/admin_gallery.php on line 20

 

Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: './uploads/background.png' is not a valid JPEG file in /home/cobi/public_html/admin_gallery.php on line 20

 

Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home/cobi/public_html/admin_gallery.php on line 35

Link to comment
Share on other sites

You are already inserting it after selecting it. If you do this:

SELECT * FROM sometable...
INSERT INTO sometable...

you're selecting everything, then inserting a new row. You need to change it to this:

INSERT INTO sometable...
SELECT * FROM sometable...

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.