Jump to content

trying to make thumbnails upload connected with mysql (help plz)


Darkwoods

Recommended Posts

im trying to change my edit page where i upload my thumbnails..

 

what im trying do is when the image upload form/input is empty for example i dont want it to change because now when i try to edit only the text on the edit page and update it remove the file name from mysql table

 

and here where my problem is wan it to take the information from the file/input when i got somethingin it how do i do that?

<?php
include "../admin/inc/header.php";
$id = $_GET['id'];
if(isset($_POST['submit']))

  {  
      $bkname = $_POST['bkname'];
  $content = $_POST['content'];
  $thefile2=$_FILES['thefile']['name'];

		if(!$bkname){
                     echo "Error: Page Name is a required field. Please fill it.";
                     exit(); }					 

		if(!$thefile2){
		echo $row['thefile'];
				}

  	$result = mysql_query("UPDATE latest SET thefile='$thefile2', bkname='$bkname', content='$content' WHERE id='$id' ",$connect) or die(mysql_error());
        echo "<b>Successfully Edited</b>";
          // echo "<meta http-equiv=Refresh content=2;url=index.php>";
}
elseif($id)
{

        $result = mysql_query("SELECT * FROM latest WHERE id='$id' ",$connect) or die(mysql_error());
        while($row = mysql_fetch_assoc($result))
             {
                $bkname = $row['bkname'];
                $content = $row['content'];
			$thefile2 = $row['thefile'];
			 ?>
                

<form name='form1' method='post' action='<?php echo $_SERVER['PHP_SELF'] ?>?id=<?php echo $row['id']?>' enctype='multipart/form-data'>
<input type="hidden" name="id" value="<?php echo $row['id'];?>">

   
Book Name:		<input name="bkname" size="40" maxlength="255" value="<?php echo $bkname; ?>" /><br />
Book Info:		<textarea name="content"><?php echo $content; ?></textarea><br>
Select File:	<input type='file' name='thefile'><br>
    				<input type="hidden" name="thefile" value="<?php echo $row['thefile'];?>">
                    
				<input type='submit' name='submit' value='upload'><br /><br />
       <?php
	echo '<img src="../uploads/thumbs/thumb'. $row['thefile'] . '" hspace="5" vspace="5" align="left" />'; 
  } 



echo '</form>';
  

     $new_height=175;
     $new_width=175;

     $allowed_types = array( 
     'image/pjpeg', 
     'image/gif', 
     'image/png', 
     'image/jpeg'); 

     if(in_array($_FILES['thefile']['type'], $allowed_types)) 

     {
       copy ($_FILES['thefile']['tmp_name'], $_FILES['thefile']['name']) or die ("Could not copy");

       echo "Name: ".$_FILES['thefile']['name']."";
       echo "Size: ".$_FILES['thefile']['size']."";
       echo "Type: ".$_FILES['thefile']['type']."";  

       $imagefile=$_FILES['thefile']['name'];

       list($width, $height) = getimagesize($_FILES['thefile']['name']);
       $image_p = imagecreatetruecolor($new_width,$new_height);
   

       if ($_FILES['thefile']['type'] == "image/gif") 
       {
           $img = @imagecreatefromgif($imagefile);

           imagecopyresampled($image_p, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
           $thename=$_FILES['thefile']['name'];
           $thenames="thumb$thename";
           $location="thumbs/$thenames";
           imagegif($image_p,$location, 100);
       }
       else
       {

         $img = @imagecreatefromjpeg($imagefile);
         imagecopyresampled($image_p, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
         $thename=$_FILES['thefile']['name'];
         $thenames="thumb$thename";
         $location="thumbs/$thenames";
         imagejpeg($image_p,$location, 100);
       }
     }

     else

     {
       print "<br>Only Gifs and Jpegs are supported. Back to <A href='../admin/test.php'>Control Panel</a>";
     }
}

include "../admin/inc/footer.php";
  
?>

 

 

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.