| Author |
Message |
floppy

Joined: Nov 29, 2006
Posts: 85
Location: Jackson, Mississippi
|
Posted:
Sat Dec 30, 2006 9:34 pm |
|
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;
} |
|
| |
|
|
 |
gotcha
Site Admin


Joined: Oct 25, 2004
Posts: 921
|
Posted:
Sat Dec 30, 2006 11:18 pm |
|
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. |
| |
|
|
 |
floppy

Joined: Nov 29, 2006
Posts: 85
Location: Jackson, Mississippi
|
Posted:
Sun Dec 31, 2006 11:57 am |
|
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. |
| |
|
|
 |
gotcha
Site Admin


Joined: Oct 25, 2004
Posts: 921
|
Posted:
Sun Dec 31, 2006 1:19 pm |
|
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. |
| |
|
|
 |
floppy

Joined: Nov 29, 2006
Posts: 85
Location: Jackson, Mississippi
|
Posted:
Sun Dec 31, 2006 4:05 pm |
|
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 |
|
|
 |
floppy

Joined: Nov 29, 2006
Posts: 85
Location: Jackson, Mississippi
|
Posted:
Sun Dec 31, 2006 4:24 pm |
|
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 |
|
|
 |
gotcha
Site Admin


Joined: Oct 25, 2004
Posts: 921
|
Posted:
Sun Dec 31, 2006 4:36 pm |
|
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]); |
|
| |
|
|
 |
floppy

Joined: Nov 29, 2006
Posts: 85
Location: Jackson, Mississippi
|
Posted:
Mon Jan 01, 2007 11:42 am |
|
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. |
| |
|
|
 |
|
|