I'm having problems with my file upload code. If I start to upload
files larger than a approx 400k the page seems to time out and I get a
page cannot be displayed error.
I have checked the php.ini on the server and max file size is 2Mb and
max Post size is 8Mb.
I initially thought that the script was timing out and breaking off mid
upload so I added the set time limit command which changed absolutely
nothing. I also tried to get the script to show all errors but I don't
get anything output at all. When I choose the file and click upload I
either get a blank white screen with no error messages or a 404 page.
The code works fine with images under approx 300k and the page is
calling itself so its not a case of me trying to send the information to
a page that doesn't exist.
I have spent an age searching through google and the manual but I can't
find anything that relates to this particular problem
If anybody has any ideas I would be most grateful, I have included my
upload code below (hopefully the formatting wont be lost on upload but I
bet it is)
Mark
error_reporting(E_ALL);
set_time_limit(0);
$successful_creation=FALSE;
//Check if user is adding a screenshot
if (isset($_POST['add']))
{
else if (!empty($_FILES['browselocal']))
{
$choose_source = "browselocal";
//Check that the user is uploading a JPEG
$image_properties =
@GetImageSize($_FILES[$choose_source]['tmp_name']);
if ($image_properties[2] == 2)
{
//Upload the file to remote server
$upload_file = $UPLOAD_DIRECTORY .
$_FILES[$choose_source]['name'];
//If a file with this name already exists modify the name of
the file
so that you don't overwrite anything.
while (file_exists($upload_file))
{
$add_random_number = rand(0, 9);
$_FILES['Browse']['name'] =
$add_random_number.$_FILES[$choose_source]['name'];
$upload_file = $UPLOAD_DIRECTORY .
$_FILES[$choose_source]['name'];
}
$upload_remote_location =
"http://".$_SERVER['HTTP_HOST'].$UPLOAD_REMOTE.$_FILES[$choose_source]['name'];
$thumbnail_file = $UPLOAD_DIRECTORY ."thumb".
$_FILES[$choose_source]['name'];
$thumbnail_remote_location =
"http://".$_SERVER['HTTP_HOST'].$UPLOAD_REMOTE."thumb".$_FILES[$choose_source]['name'];
//Copy the file to specified directory on the remote server
copy($_FILES[$choose_source]['tmp_name'], $upload_file);
//Create a new image that will be turned into a thumbnail
$working_image =
ImageCreateFromJPEG($_FILES[$choose_source]['tmp_name']);
$current_x = ImageSX($working_image);
$current_y = ImageSY($working_image);
if ($current_x > $current_y)
{
//Set the width of the image and work out what the
height will be
making sure the image keeps its current scale
$new_x=124;
$scale_x = $new_x/($current_x-1);
$new_y = $current_y*$scale_x;
}
else
{
//Set the height of the image and work out what the
width will be
making sure the image keeps its current scale
$new_y=93;
$scale_y = $new_y/($current_y-1);
$new_x = $current_x*$scale_y;
}
//Create the thumbnail
$thumbnail_image = imagecreatetruecolor($new_x,$new_y);
ImageCopyResampled($thumbnail_image, $working_image, 0, 0, 0,
0,
$new_x, $new_y, $current_x, $current_y);
//Save the thumbnail to remote server
imagejpeg($thumbnail_image,$thumbnail_file,100);
//Destroy the images in memory that were used to create the
thumbnail
imagedestroy($working_image);
imagedestroy($thumbnail_image);
//Report back that image creation has been successful
$successful_creation=TRUE;
//Add the screenshot data to the screenshot table
if (!mysql_db_query($DB, "Insert into
".$SCREENSHOT_TABLE."(thumbnail, pictureurl, picturename, alttext,
page_id, screen_id, thumblocal, piclocal)
Values('$thumbnail_remote_location','$upload_remote_location','$name','$alt','$pageid','$screenid','$thumbnail_file','$upload_file')"))
{
DisplayErrMsg(sprintf("Error adding screenshot")) ;
DisplayErrMsg(sprintf("error:%d %s",
mysql_errno($link),
mysql_error($link))) ;
exit() ;
}
}
//If user has not uploaded a JPEG display an error message
else {Die("Invalid File Type!!! You can only upload JPG's.")) ;}
}
}
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php