Google

NukeCoder


View next topic
View previous topic
Post new topic   Reply to topic
Author Message
floppy




Joined: Nov 29, 2006
Posts: 85
Location: Jackson, Mississippi

PostPosted: Sat Dec 30, 2006 9:34 pm
Reply with quote

I would like to return my $filename from this function. It does not seem to want to play. I need to create a thumbnail from it after its uploaded if the image size is greater than 400.

Here is function upload
Code:
function upload($imgprefix, $image, $updir){
$jpeg = 'image/jpeg';
$jpg = 'image/pjpeg';
$gif = 'image/gif';
$png = 'image/png';
//CHECK THE IMAGE
if ($_FILES["image"]["size"] > 0){
$image_name = $_FILES['image']['name'];
$image_type = $_FILES['image']['type'];
$image_size = $_FILES['image']['size'];
$temp_file_name = $_FILES['image']['tmp_name'];
if ($image_name != '' && ($image_type != $jpg && $image_type != $jpeg && $image_type != $gif && $image_type != $png)){
OpenTable();
echo '<center>('.$image_name.') Your Extension is not Allowed</b></center><br/>';
echo '<center><b>'._GOBACK.'</b></center><br/>';
CloseTable();
crcopy();
include("footer.php");
die();
} else {
if($image_type == $jpg){$file_ext = "jpg";}
if($image_type == $jpeg){$file_ext = "jpg";}
if($image_type == $gif){$file_ext = "gif";}
if($image_type == $png){$file_ext = "png";}
$filename = $imgprefix.time().".".$file_ext;
$filename = str_replace(' ', '_', $filename);
$target_path = "$updir/$filename";
//RETURN ERROR IF THE FILE CANNOT BE RENAMED AND MOVED PROPERLY
if(!move_uploaded_file($_FILES['image']['tmp_name'], $target_path)){
OpenTable();
echo '<center><span class="title">Sorry there was an error</span><br \>Be Sure Your Image Directory is chmod 777 and your image is the correct file type</center><br /><br />';
echo '<center><b>'._GOBACK.'</b></center><br/>';
CloseTable();
crcopy();
include("footer.php");
die();
}
 }
} else {
$filename = '';
}
return $filename;
}
 
View user's profile Send private message Visit poster's website MSN Messenger
gotcha
Site Admin
Site Admin



Joined: Oct 25, 2004
Posts: 921

PostPosted: Sat Dec 30, 2006 11:18 pm
Reply with quote

It would probably be easier to do if you broke it up into 2 functions.
One to handle the upload and the other to handle the image thumbnail.
 
View user's profile Send private message Visit poster's website
floppy




Joined: Nov 29, 2006
Posts: 85
Location: Jackson, Mississippi

PostPosted: Sun Dec 31, 2006 11:57 am
Reply with quote

I am doing that. The biggest problem is this if the function will not return the renamed filename to the script. I can't call that filename to be thumbnailed.

My other alternatives is to take the renaming process out of the function and do it before.

Code:
$filename = $imgprefix.time().".".$file_ext;
$filename = str_replace(' ', '_', $filename);


It would work better to my benefit if I could just get it to return my filename though.
 
View user's profile Send private message Visit poster's website MSN Messenger
gotcha
Site Admin
Site Admin



Joined: Oct 25, 2004
Posts: 921

PostPosted: Sun Dec 31, 2006 1:19 pm
Reply with quote

I think this line....

Code:
if(!move_uploaded_file($_FILES['image']['tmp_name'], $target_path)){


should be

Code:
if(!move_uploaded_file($_FILES['image']['tmp_name'], $updir)){


giving it the directory instead of the directory & filename.

also i would have it return false; instead of an empty filename if it fails.
 
View user's profile Send private message Visit poster's website
floppy




Joined: Nov 29, 2006
Posts: 85
Location: Jackson, Mississippi

PostPosted: Sun Dec 31, 2006 4:05 pm
Reply with quote

Nah using $updir there just returns an that error.

My only problem is this, If you follow the code below you will see I need to use the renamed filename again.

Code:
upload($username, $image, $crfig[amempath]);
//$db->sql_query("update ".$prefix."_croster_members set gid='$gid',rid='$rid',fid='$fid',cusername='$cusername',mimage='$filename',mthumb='$filename',location='$location',age='$age',interest='$interest',
ogames='$ogames',email='$email',aim='$aim',msn='$msn',yahoo='$yahoo',xfire='$xfire' where uid='$uid'");
$size = getimagesize("$crfig[amempath]/$filename") OR die("NO IMAGE FOUND");
$width = $size[0];
if($width >= 400){
$imagetype = $_FILES['image']['type'];
thumbnail($username, $filename, $imagetype, $crfig[amemthbpath]);
}
Header("Location: ".$admin_file.".php?op=CRMain");
}


Last edited by floppy on Sun Dec 31, 2006 4:24 pm; edited 1 time in total 
View user's profile Send private message Visit poster's website MSN Messenger
floppy




Joined: Nov 29, 2006
Posts: 85
Location: Jackson, Mississippi

PostPosted: Sun Dec 31, 2006 4:24 pm
Reply with quote

What would be ideal is if I could check the image size inside the function and if larger then 400 px in width create a thumbnail and upload to a new directory. Images kick my butt everytime.

P.S If you want to keep code and quotes from stretching your tables. Try
http://www.phpbb.com/phpBB/viewtopic.php?t=229348. I don't think it requires any conversion to bbtonuke.


Last edited by floppy on Sun Dec 31, 2006 4:45 pm; edited 1 time in total 
View user's profile Send private message Visit poster's website MSN Messenger
gotcha
Site Admin
Site Admin



Joined: Oct 25, 2004
Posts: 921

PostPosted: Sun Dec 31, 2006 4:36 pm
Reply with quote

if the function upload is returning the filename you will need to change


Code:
upload($username, $image, $crfig[amempath]);


to

Code:
$filename = upload($username, $image, $crfig[amempath]);
 
View user's profile Send private message Visit poster's website
floppy




Joined: Nov 29, 2006
Posts: 85
Location: Jackson, Mississippi

PostPosted: Mon Jan 01, 2007 11:42 am
Reply with quote

I got this resolved ended up stripping the upload function. Maybe at a later date I will go back and try to implement it for my needs.
 
View user's profile Send private message Visit poster's website MSN Messenger
Display posts from previous:       
Post new topic   Reply to topic

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 5 Hours
Forums ©