Nov 22, 2009

My Code Doesnt Resize Large Images, Please Help.

free web hosting
Open Discussion > MODERATED AREA > Computers > Programming Languages > PHP Programming

My Code Doesnt Resize Large Images, Please Help.

apple
Can someone please have a look at the following code, this uploads an image, and make it in 2 sizes, one size is max. 600 x 800, uploads to images folder and second 120 x 120 and uploads to thumbs folder.
this script works fine, with normal size images, but if i try to upload large pics( for example, an image with dimension 2432 x 3300, it shows blank page, and uploads the original image without sizing to "image" folder, and doesnt make any small thumbnail... I hope u understand..
Please someone help me, i shall be so thankful.

CODE

<?PHP
session_start();
header("Cache-control: private");

function Resize_Image($save,$file,$t_w,$t_h,$s_path,$o_path) {
$s_path = trim($s_path);
$o_path = trim($o_path);
$save = $s_path . $save;
$file = $o_path . $file;
$ext = strtolower(end(explode('.',$save)));
list($width, $height) = getimagesize($file);

if(($width>$t_w) OR ($height>$t_h)) {
$r1 = $t_w/$width;
$r2 = $t_h/$height;

if($r1<$r2) {
$size = $t_w/$width;

}else{
$size = $t_h/$height;


}
}else{
$size=1;
}
$modwidth = $width * $size;
$modheight = $height * $size;


$tn = imagecreatetruecolor($modwidth, $modheight);

switch ($ext) {
case 'jpg':
case 'jpeg':
$image = @imagecreatefromjpeg($file) or die ("Seems to be problem");
break;
case 'gif':
$image = imagecreatefromgif($file);
break;
case 'png':
$image = imagecreatefrompng($file);
break;
}
imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) or die("he");
imagejpeg($tn, $save, 100) or die ("heheh");;
return;
}

function write_beg($filename, $data){
$handle = fopen ($filename, "r");
$old_content = fread ($handle, filesize ($filename));
fclose ($handle);
$final_content = $data.$old_content;
$handle2 = fopen ($filename, "w");
$finalwrite = fwrite ($handle2, $final_content);
fclose ($handle2);
}


# check to see if form submitted
# if yes, process form variables

# if no, display form

if($_POST["action"]== "Upload Image"){

# define the constant variables

$uploadDir = 'images/'; // main picture folder
$max_height = 600; // largest height you allowed; 0 means any
$max_width = 800; // largest width you allowed; 0 means any
$max_file = 2000000; // set the max file size in bytes
$image_overwrite = 1; // 0 means overwite; 1 means new name
$allowed_type01 = array(
"image/gif",
"image/pjpeg",
"image/jpeg",
"image/png",
"image/x-png",
"image/jpg"); // add or delete allowed image types
$do_thumb = 1; // 1 make thumbnails; 0 means do NOT make
$thumbDir = "thumbs/"; // thumbnail folder
$thumb_prefix = ""; // prefix for thumbnails
$thumb_width = 120; // max thumb width
$thumb_height = 120; // max thumb height
$flat_file = 1; // 1 flat file for data; 0 database
$what_error = array();

# get basic info about uploaded file
$original_name = $_FILES['imagename']['name'];
$original_tmp = $_FILES['imagename']['tmp_name'];
$original_size = $_FILES['imagename']['size'];
$original_type = $_FILES['imagename']['type'];

# do some basic error trapping and cleanup
if($original_size>$max_file) {
//too large, go back to form
array_push($what_error, "File Size Exceeds Limit");
}

if( $original_size<1) {
//no file was uploaded
array_push($what_error, "Please Select A File To Upload");
}

if(!in_array($original_type, $allowed_type01)) {
// wrong file type
array_push($what_error, "File Type Is Not Allowed");
}

if(count($what_error)>0) {
// send to error page
$_SESSION["resultset"] = $what_error;
echo $what_error;
//echo '<meta http-equiv="refresh" content="0;URL=mpg_error.php"> ';
exit();
}

# check to see if file already exists in the folder
# if it exists AND rename option is , create new name
$does_it = FALSE;
$original_name = strtolower($original_name);
if(file_exists($uploadDir . $original_name)) {
if($image_overwrite == 1) {
//rename
while(!$does_it) {
$add_this_name = rand(1,200);
$original_name = $add_this_name . $original_name;
if(!file_exists($uploadDir . $original_name)) {
$does_it = TRUE;
}
}
}
}

# attempt to MOVE the image to its proper location

$uploadFile = $uploadDir . $original_name;
if (move_uploaded_file($_FILES['imagename']['tmp_name'], $uploadFile) ) {
// continue
} else {
// send to error page
array_push($what_error, "error - unknown cause");
$_SESSION["resultset"] = $what_error;
echo "error - unknown cause";
//echo '<meta http-equiv="refresh" content="0;URL=mpg_error.php"> ';
exit();
}

# check to see if image needs resizing and act accordingly

list($original_width, $original_height) = getimagesize($uploadDir . $original_name);
//echo $original_height;

if($max_height<$original_height OR $max_width<$original_width) {
// dimensions are too large - resize
Resize_Image($original_name,$original_name,$max_width,$max_height,$uploadDir,$uploadDir);
echo "image resized done<br>";
}



# check to see if make thumbnails is true
# if yes make and store thumb
$thumb_name = $thumb_prefix . $original_name;

if($do_thumb == 1) {
// make a thumb
Resize_Image($thumb_name,$original_name,$thumb_width,$thumb_height,$thumbDir,$uploadDir);
echo "thumb too";
}


}else{
?>
<html>
<head>
<title>My Photo Gallery Upload Form</title>
<link rel="stylesheet" type="text/css" href="shared_files/textsize.css">

</head>
<body bgcolor="#ffffff" text="#0000a6" link="#0000a6" vlink="#0000a6" alink="#0000a6">

<div style="position: absolute; top: 50px; left: 300px; width:90%; font-size:10pt; padding:10px;filter:shadow(color:gray);"><div style="HEIGHT:250px; border : solid 2px #0000a0; padding : 4px; WIDTH:380px; OVERFLOW:auto; background-color:#fcfcfc; layer-background-color:#fcfcfc; visibility: visible; ">
<form action="<?php echo $PHP_SELF ?>" method="post" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
Browse a File to Upload: <br>
<input type="file" name="imagename"><br>
Enter a title for the picture<br>
<input type="text" name="imagetitle" size="40" maxlength="80" value=""><br>
Enter your name<br>
<input type="text" name="artistname" size="40" maxlength="80" value=""><br>
Enter a description for the picture<br>
<input type="text" name="imagedescript" size="40" maxlength="250" value=""><br>
<input type="submit" value="Upload Image" name="action"><br><br>
note: <font color="#ff0080">max file size is: 2megs</font>
</div></div>
</body>
</html>
<?PHP
}

?>

Notice from truefusion:
Placed code into codebox.

 

 

 


Comment/Reply (w/o sign-up)

jlhaslip
Just wondering if the file size for those really LARGE images exceeds the max file size for uploads?

How many megs are they and what are the server limits for max file size?

Comment/Reply (w/o sign-up)

ghostrider
The fact that only large files don't work makes me think that the script is not working due to a lack of memory. I believe Trap17 allocates 4 megabytes of RAM for each account to use, and no more. I'm not familiar with the internal workings of the image functions of PHP, but it could be very likely its converting the file to a different (and probably larger) format, so that it can be manipulated by all the imaging functions of PHP with ease.

My advice: Get a server with PHP running on your own computer, and try it there. If it works, its a memory problem. If it doesn't, post back smile.gif.


Comment/Reply (w/o sign-up)



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : code, doesnt, resize, large, images,

  1. Php Code For Login Form With Validation In Php
    (7)
  2. Create Table - Mysql Code - Help
    (1)
    I need your feedback about setting the database issues. Please, review them and correct some entries
    in the code if they got some mistakes. This is the code itself: SQL CREATE TABLE `news` (
    `id` int(250) NOT NULL auto_increment, `title` varchar(255) NOT NULL default '',
    `text` text NOT NULL, `author` varchar(255) NOT NULL default '', `valid` varchar(255)
    NOT NULL default '', `date` varchar(255) NOT NULL default '', PRIMARY KEY
    (`id`) ) ENGINE = MyISAM ; ....
  3. Php Source Code Unveiled In Browser?
    is that possible? (7)
    I am quite new to PHP and this concern came to my mind after playing around a bit with it... When
    PHP is not correctly configured on the web server the source code of a php file we try to access
    through a browser will be shown instead of the result of the code itself. This will normally not
    happen when PHP is working properly, but I was just wondering if it could still be possible to see
    that code if a user wanted to or if something on the server failed. This would for example expose
    sensitive information like mysql passwords and so on... Is anything like that possib....
  4. Malicious Code Injection
    (3)
    Hi everyone! This is my first post, so be kind! Basically, I'm trying to get a free host
    together so am writing some posts. Here's a little summin' summin' about malicious code
    injection with PHP applications. Basically, this security exploit is one of the oldest tricks in
    the books and all comes down to the fact that PHP allows execution of both local and remote scripts
    with the SAME function... dur. Anyway, this is how it works. Image you've just employed a young
    go getter, straight outta uni, who has found becoming a Jack of all trades a sinch. Y....
  5. Php And Mysql Programming
    anyone knows a code for mysql and php (2)
    hi everyone! I am making a program using php and mysql...I am a noob on this so i need your help
    guys...I want to make a simple program that will some values and then store them on a database and
    then retrieve them...uhmm let me give an example out put of what i need. This is the example say..:
    Enter First Name: Enter Last Name:
    Enter Age: Enter Address: ..those are the
    data needed for input values...my question now is how can I make a database whi....
  6. Php Code Needed Iii
    (10)
    Hello, everyone. I need your help again! Who might create the PHP code, the picture is above
    this text. Basically, I want when the user fill in all the information in this form, it
    automatically was sent to my email. And, then, the dialog box appears or on the same window, it was
    said that your request has been sent. Moreover, if the user did not fill the entire information,
    the dialog box appears stating that you did not fill some field. Thanks, for help. You always do
    that.....
  7. Php Code?
    Mathematical Applications (12)
    Hello, everyone. The help is needed again. How can I make calculator in PHP language? That will act
    like that a user just type in the fields known values, then click the button, and it's going to
    be solved automatically. In other words, have can I write a formula in PHP, how to plug it inside
    that language. For example, the formula to find a peremeter of square is: P=4a. So, a user
    just can write the known value which is peremeter itself and it will find the side of a square; and
    vice versa. If you can write many things how to do such formulas, such as comp....
  8. Php Code Needed
    Working Together? (5)
    Hello, everyone. I need your help again. This forum is quite good for it. Well, I need create a
    registration form for my web-site using PHP and SQL. The information it should contain: 1) User
    Name 2) First Name 3) Last Name 4) Password 5) e-mail Address 6) Security Image: that images helps
    to protect a random registration, for instance, 56+2=where user have to type an answer in order to
    finish registration. That's all for today. Anymore things, I will post another post over here.
    ....
  9. How To Display Images Of A Directory
    (5)
    I am trying to do a simple thing. I want to display all the images of a directory on a single page
    with the checkbox next to each image, so that i can select multi images and i can delete selected
    images. Following few lines of code display the images of a directory.. i need help to put the
    check boxes with each image. and I dont understand how can i select multi images with check box and
    then delete them. I hope someone can help. thanks. CODE $path = "./"; $dir_handle =
    @opendir($path) or die("Unable to open folder"); while (false !== ($file = readdir($dir_han....
  10. Php Code
    Needed?! (15)
    Well, I am a novice in PHP programming, so there is a script which I wanna get: 1. You go the
    web-site 2. On the main screen, there is a some kind of field windows, the one you get used to type
    in, when you go to google, for instance. 3. He or she types her email address and it's going to
    be saved in my SQL database. 4. That's it. Help me if you can.....
  11. Use Rss In Php Code
    (3)
    so, how can I make RSS reader on my website? thanks in advance....
  12. Will This Code Work
    php linking script ?p= (5)
    hi i'm not that great at php so i'm not to sure if this will work or not. but what i want to
    do is be able to use ?p=staff or what ever page name, with out the php extion, and i would like to
    no if this simple script i made would work. the code is: CODE $p = $_GET ; if ( !empty($p) &&
    file_exists('./' . $p . '.php') && stristr( $p, '.' ) == False ) { // pages
    = directory where you store your pages    $file = './' . $p . '.php'; } else { //
    1.php =  defult page    $file = './index.php'; } include $file; ?> ....
  13. I Need Some Proof Reading For My Code Please! [resolved]
    (7)
    Well... everything is fine except the Content Select section (refer to the in-code headings)...
    thats where it says the error is... could anyone find out why it wont work when I click one of my
    links? http://2kart.trap17.com/progress.php for an example of what happens...
    //----------------- //portfolio paths //----------------- $portfolio = "/portfolio"; $lay =
    "/images"; //------------------ //navigation //------------------ $link = ·   Home html; $link
    = ·   Portfolio html; $link = ·   Programming html; $link = ·   Graphics html; $link
    = ....
  14. Html Code Tester. Online Script
    (15)
    Yes, yes. I have another script that I have written and I am distributing. I am not entirely sure if
    this works. I have not tested it yet, but I will later and post back with a demo and fix it up.
    Current script: CODE //Save this as something like htmltest.php function CheckForm() {
    $html_unsafe=$_POST ; //Gives us our user input $html_safe=str_replace(" //Starts security measures
    $html_safe=str_replace("?>"," ",$html_safe); //User input now secure server side //Still security
    issues client side echo $html_safe; //echos our statement } //End function //Main script....
  15. Awesome Source Code Viewer Script
    (7)
    Hello! I have just came up with a sweet script to show the source code of any website and it only
    requires one file. This is the basis of the script and can be customized with CSS and other things
    and can be instituted as a public resource. Well I will provide the code and a step-by-step tutorial
    on each of its parts. This code has been tested by me. Enjoy! CODE //This little tag starts
    our php script and is easily the most important part of the script. //We will start our base script
    here. //You can change some of the styles used here to your desired color. if (....
  16. Whats Wrong>?
    please see this piece of code and see whats wrong: (9)
    CODE require('connection2.php'); $select=mysql_query("SELECT * from `users` WHERE
    password='$_GET '"); $co=mysql_num_rows($select); if ($co = 1) { session_start();
    $s=session_id(); $_SESSION ="yes"; $username=$_GET ; header("location:../main/index2.php?a=$_GET
    &s=$s"); //echo " Proceed to Game "; //echo $s; } Now that is a bit of my script for my
    login script to authenticate and stuff. Recently my game went down because there was some error in
    this. So i kept on trying and it didnt work. Now i found out, wait first let me tell you th....
  17. How To Make A Random 7 Number Code?
    (2)
    I am making a script in php, and for it I need to know how to make a random 7 digit code. I think it
    has something to do with md5, but i am not sure. Thanks! EDIT- Can someone please change the title
    to "How to make a random 7 digit code in php?" Thanks!....
  18. Php Education Class (first Code)
    (0)
    Hi I want to educate some PHP codes that i think they will be useful for all of you! My 1st code is
    this: CODE class calculator {          /**      * Variable for holding all the numbers to add
         *      * @var array      */     private $numbers = array();          /**      * Variable
    holding all the digits after the point      *      * @var array      */     private $afterPoint =
    array();          /**      * Maximum number of digits after the point      * that a number has     
    *      * @var int      */     private $afterPointLength = 0;          /**      * Fi....
  19. Some Basic Php Code Snippets For All Levels Of Experience
    (3)
    Most of the code snippets are usually used for community driven sites but they do give some general
    idea on how php works. Don't forget if your starting out php for the first time that when
    saving php files that you need to have the .php extension on your files or they will not work.
    Display Browser info This piece of code displays a user's browser info on how they are seeing
    the website CODE Actual Display- QUOTE Firefox - Mozilla/5.0 (Windows; U;
    Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3 Internet Explorer ....
  20. Use Bb Code On Your Site!
    Just like on forums! (7)
    To use this you must have PHP support on your server. Just use this code: CODE $content =
    "Hello, World!"; $html = array(' ', ' ', ' ', ' ', ' ',
    ' '); $replacements = array (' ', ' ', ' ', ' ', '
    ', ' '); $content = str_replace($html, $replacements, $content); ?> This code can
    be very useful. It can be used for word filters to block the use of bad words on your site or for
    emoticons.....
  21. Display The Current Date/time
    With a simple PHP code (4)
    Use this code to display the current date and time. CODE   $date = date('l dS \of F Y
    h:i:s A');   echo "$date"; ?> "l" would display the current day of the week such as
    Sunday. d displays the day of the month... such as 1 and S adds the appropriate suffix(st). /of
    simply displays the word "of". F displays the current month with no abbreviations while Y displays
    the four digit year(2007). "h" displays the current hour with leading zeros if necessary(Ex. 06 for
    6 o'clock). "i" displays the minute of the hour with leading zeros if necessary. ....
  22. Wap Source Code Viewer
    Mobile/wap source code viewer page (4)
    This is a source code viewer that will workl on wap/mobile sites but you can easily convert it to
    work on web im sure ;-) CODE header("Content-Type: text/vnd.wap.wml"); echo '
    ';   print " "; if ($url == "") {      echo " Enter url: »View source code ";   }
    if ($url == "$url") {    $udata=@file_get_contents("$url"); $udata = str_replace("$","$$",$udata);
    $udata = str_replace("&","&",$udata); $udata = str_replace("'","'",$udata); $udata =
    str_replace(" $udata = str_replace(">",">",$udata); $udata = str_replace("\"....
  23. Requesting Auto Generating Id Tag In Php Code
    Php Coding (3)
    Hello...I'm designing a website in PHP where ppl can submit their links for "cool sites".
    Anyway, when somebody submit's a link to a website for example "http://www.google.com" it
    creates an id such as "index.php?id=1134411593". I dont want the links to be converted into
    id's. I want it to remain as "http://www.google.com". I have the following coding on
    ( echo " ). I'm a novice. Please Help!!!! Thanks... Plus I
    also want to add the date on when the link was submitted. Please follow our forum rule by making....
  24. Dynamic Image / Signature Generator
    a simple code to change text on an image (12)
    In search of dynamically changing quote, saying or all other types of text on an image I came across
    a code that I have modified to fit my initial usage. This procedure requires two files and short
    knowledge of PHP. If you are familiar with Trap17's sig rotation code you will understand this
    procedure very fast. Code 1: dynamic_sig.php (you can rename this to index.php and you'll see
    at the end why) Code 2: a simple text file named anything (I will call it name.txt ) Code 1
    CODE header("Content-type: image/png"); $image = imagecreatefrompng("../i....
  25. Adapting Html Code Embed To Work On Phpnuke
    Help With This Html Code Pls (7)
    QUOTE how can get this html code to work on my phpnuke site? what tags would i
    have to enable in the $Allowable HTML part of my config.php file?? Edited topic title. Moved to
    Programming. ....
  26. Can You Add Images Into A Mysql Database?
    Using Php? (23)
    I'm learning php in class right now, but I'm still not that good at it, what I'm
    wondering is when I write the php so that it can connect with a database, can I at the same time
    have it that it is able to display back images that I choose. Like, I want a search feature, where
    you can search for a keyword, and it will bring back a list of all the possible entries with that
    keyword, but each of these entries will have a photo associated with it. Now, do I put these image
    files directly into the database, or do I write the code to link them from my files to th....
  27. Change Permission With Php Code
    code to change files' and folders' permissions? (3)
    As everyone know, there two ways (that I can think of) to change files' and directories'
    permissions. One is to change it in your cPanel's Disk Manager and the other is with an FTP
    client that supports chmod. Well, I'm doing something for my site that requires files to have
    full permissions (Execute, Write, and Read on all three groups). At first, I thought that if I made
    the directory 777, then every file created in that directory will be 777 as well. I'm wrong. An
    alternative to doing this is to change each file permission myself, but that would be....
  28. Get Filename Of Referring Url
    php code to get filename of referring URL (9)
    Hey /smile.gif' border='0' style='vertical-align:middle' alt='smile.gif' /> I want to know how
    to get the filename of the referring URL. Look at the following example: Page A which has a URL of
    http://blah.trap17.com/blah/blah1.php redirects the user to Page B which has a URL of
    http://blah.trap17.com/blah/blah2.php . Is there a PHP code that I can put on blah2.php that will
    output blah1.php? I tried _SERVER ; (please note the code may not exactly be correct as I do not
    remember the code /laugh.gif' border='0' style='vertical-align:middle' alt='laugh.gif' />....
  29. Php Clock
    source Code (8)
    Hi Every one i find this code its very easy simple php clock i think you can use it /blink.gif'
    border='0' style='vertical-align:middle' alt='blink.gif' /> CODE // Binary Clock // script
    copyright© 2002 Andreas Tscharnuter // questions? contact: psychodad@psychodad.at ||
    http://www.psychodad.at/clock/ // free to use, copy and modify but leave comments untouched;) //
    just include this file where your binary clock should appear // version 1.2   03 September 2003 //
    below you can change different settings // and remember to drink m000re milk! $size =  "40";  ....
  30. How do you test your php code
    (97)
    We know that php is a server side scripting language. So we will need a server with the php parser
    to parse/test our code. How are you doing that. Do you upload it to a server for testing or did you
    instal php and the server (apache) on your computer (localhost)....

    1. Looking for code, doesnt, resize, large, images,

Searching Video's for code, doesnt, resize, large, images,
See Also,
advertisement


My Code Doesnt Resize Large Images, Please Help.

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com