Help - Search - Members - Calendar
Full Version: filesize() on uploaded files not working
Invision Power Services > Community Forums > Community Web Design and Coding
aoLhaTer
Ive modified the post.php file so that it resizes and recompresses user uploaded images that are too large
The modification works great but on the line that sets the new filesize of the recompressed file
CODE
$attach_data['attach_filesize'] = @filesize( $upload->saved_upload_name ); //specify filesize after resample

..doesnt actually write the new filesize to the variable. The filesize() variable instead reads the file and for whatever reason returns the old filesize and not the new one! Im completely baffled by this

Heres the entire block of code
CODE
if ( $upload->saved_upload_name and @file_exists( $upload->saved_upload_name ) )
{


$attach_data['attach_filesize'] = @filesize( $upload->saved_upload_name );
$attach_data['attach_location'] = $upload->parsed_file_name;
$attach_data['attach_file'] = $upload->original_file_name;
$attach_data['attach_is_image'] = $upload->is_image;
$attach_data['attach_ext'] = $upload->real_file_extension;


if ( $attach_data['attach_is_image'] == 1 )
{
$thumb_data = $this->create_thumbnail( $attach_data );
$img_size = @GetImageSize( $upload->saved_upload_name ); //hack
$attach_data['attach_dimensions'] = $img_size[0].'x'.$img_size[1]; //hack

if ( $thumb_data['thumb_location'] )
{
$attach_data['attach_thumb_width'] = $thumb_data['thumb_width'];
$attach_data['attach_thumb_height'] = $thumb_data['thumb_height'];
$attach_data['attach_thumb_location'] = $thumb_data['thumb_location'];
}

//hack
if ( $attach_data['attach_filesize'] > 409600 ) //if file is bigger than 400kb
{
$im['img_width'] = $img_size[0]; //default to current size for resampling later
$im['img_height'] = $img_size[1];

if ( $img_size[0] * $img_size[1] > 1228800 ) //if more pixels than a 1280x960 image
{
require_once( KERNEL_PATH.'class_image.php' );
$image = new class_image();

$array['max_width'] = 1280; $array['max_height'] = 960;
$array['cur_width'] = $img_size[0];
$array['cur_height'] = $img_size[1];

$im = $image->scale_image($array);
}

$image = imagecreatefromjpeg( $upload->saved_upload_name );
$imageoutput = imagecreatetruecolor( $im['img_width'], $im['img_height'] );
imagecopyresampled( $imageoutput, $image, 0, 0, 0, 0, $im['img_width'], $im['img_height'], $img_size[0], $img_size[1] );
imagejpeg( $imageoutput, $upload->saved_upload_name );
imagedestroy( $imageoutput );
imagedestroy( $image );

$attach_data['attach_dimensions'] = $im['img_width'].'x'.$im['img_height']; //rewrite dimensions after resample
echo ' '.$upload->saved_upload_name.' ';
echo filesize( $upload->saved_upload_name );
$attach_data['attach_filesize'] = @filesize( $upload->saved_upload_name ); //specify filesize after resample
}

}

$DB->do_insert( 'attachments', $attach_data );

$newid = $DB->get_insert_id();

$attach_data['attach_id'] = $newid;

$this->per_post_count += $attach_data['attach_filesize'];
$this->cur_post_attach[] = $attach_data;

return $newid;
}
}



If anyone could figure out whats going on here I would be infinitely appreciative
Im at a complete loss on this one

Thanks in advance
Rikki
Try calling clearstatcache() before the two echo's you have.
aoLhaTer
That did it!!
Wow never knew about that function (or even that PHP cached things like filesize)

Thanks a bunch Rikki, can now release my mod original.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.