Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Image Resize and upload issue (thumbs) help please
Old 12-13-2010, 04:33 PM Image Resize and upload issue (thumbs) help please
Junior Talker

Posts: 1
Name: Roozbeh
Trades: 0
Hi guys,

Im trying to resize and create thiumbnails while uploading an image but it doesnt work, as i am new to php and i have followed other tutorials, i might have made a mistake which i dont understand. i have a table called test (find attached image) and what i need is when i upload an image, it copies the location of both image and on fly created thumb into my database

i appreciate your help & please excuse me for messed up code

PHP Code:
<?php
session_start
();
include (
"../global.php");
//welcome messaage
echo "Welcome, " .$_SESSION['username']."!<p>";
$username=$_SESSION['username'];
//get user id & credit limit
$query=mysql_query("SELECT id FROM users");
while(
$row mysql_fetch_array($query))
{
$id $row['id'];
echo 
$id;
}
$credit=mysql_query("SELECT credit FROM users");
while(
$row mysql_fetch_array($credit))
{
$creditcheck $row['credit'];
echo 
"your credit is: $creditcheck";
}
    
$reference rand(11111111,99999999);










     
//image1
  
define ("MAX_SIZE","100");
   
define ("WIDTH","150");
define ("HEIGHT","100");
function 
make_thumb($img_nameone,$filenameone,$new_w,$new_h)
{
$ext=getExtension($img_nameone);
if(!
strcmp("jpg",$ext) || !strcmp("jpeg",$ext))
$src_imgone=imagecreatefromjpeg($img_nameone);
if(!
strcmp("png",$ext))
$src_imgone=imagecreatefrompng($img_nameone);
$old_x=imageSX($src_imgone);
$old_y=imageSY($src_imgone);
$ratio1=$old_x/$new_w;
$ratio2=$old_y/$new_h;
if(
$ratio1>$ratio2) {
$thumb_w=$new_w;
$thumb_h=$old_y/$ratio1;
}
else {
$thumb_h=$new_h;
$thumb_w=$old_x/$ratio2;
}
$dst_imgone=ImageCreateTrueColor($thumb_w,$thumb_h);
imagecopyresampled($dst_imgone,$src_imgone,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
if(!
strcmp("png",$ext))
imagepng($dst_imgone,$filenameone);
else
imagejpeg($dst_imgone,$filenameone);
imagedestroy($dst_imgone);
imagedestroy($src_imgone);
function 
getExtension($str) {
$i strrpos($str,".");
if (!
$i) { return ""; } $l strlen($str) - $i$ext substr($str,$i+1,$l); return $ext; }
$errors=0;
if (
$creditcheck<=0)           
Header("Location: buy-credit.php");             
          else         
if (
$creditcheck>=0){

if(isset(
$_POST['register']))
 
$submit mysql_query("INSERT INTO test (reference) 
     VALUES 
     ('
$reference')");
     





    {
$image=$_FILES['myfileone']['nameone'];
if (
$image)
{
$filename stripslashes($_FILES['myfileone']['nameone']);
$extension getExtension($filenameone);
$extension strtolower($extension);
if ((
$extension != "jpg") && ($extension != "jpeg") && ($extension != "png")) { echo '<h1>Unknown extension!</h1>'$errors=1; } else {
$size=getimagesize($_FILES['myfileone']['tmp_name']);
$sizekb=filesize($_FILES['myfileone']['tmp_name']);
if (
$sizekb MAX_SIZE*1024)
{ echo 
'<h1>You have exceeded the size limit!</h1>'$errors=1; }
$image_nameone=time().'.'.$extension;
$newname="rentimages/".$image_nameone;
$copied copy($_FILES['myfileone']['tmp_name'], $newname);

if (!
$copied) { echo '<h1>Copy unsuccessfull!</h1>'$errors=1; } else {
$thumb_name='rentimages/thumbs/thumb_'.$image_name;
$thumb=make_thumb($newname,$thumb_name,WIDTH,HEIGHT);
}} }}
if(isset(
$_POST['register']) && !$errors)
{


$locationone="rentimages/$nameone";

$image1 mysql_query ("UPDATE test SET image1='$newname', thumb='$thumb_name' WHERE reference='$referenceran'");
}
}
}
?>



<html>
<body>




  <form action='imagetests.php' method='POST' enctype='multipart/form-data'>

     
 File: <input type='file' name='myfileone'><p />

    <input type='submit' name='register' value='Update'> <p />


</body>
</html>
Attached Images
File Type: png jpeg.png (39.3 KB, 2 views)

Last edited by chrishirst; 12-18-2010 at 10:13 AM..
princeofpersia is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-14-2010, 11:30 AM Re: Image Resize and upload issue (thumbs) help please
Super Spam Talker

Posts: 879
Name: Paul W
Trades: 0
"it doesnt work" What doesn't work? What error messages? I'd suggest you break the code down and do one step at a time. For example, start with an image already on the server, get the thumbnailing working. Then, separately, do a simple image upload and move. Do another script that handles db queries -- I think you need to clarify your thinking here. PLan the overall logic of the script, the test you need to do to make sure the flow is right, then put the components together. Better than the big bang altogether approach.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE
PaulW is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Image Resize and upload issue (thumbs) help please
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.11382 seconds with 13 queries