Solved

image magick will not upload any image larger than 100KB

Posted on 2014-10-01
9
127 Views
Last Modified: 2014-10-24
Hello,  I have an upload image program that another programmer wrote a few years ago.  It uses image magick.  It has been working fine for a few years. All of the sudden it stopped uploading any images over about 100KB.  I do not have a clue what it could be.  Recently added SSL to this particular site.  But can try it at http and still cannot get it to upload any over 100KB.  Any help would be appreciated. Thanks

This is from the include
<?php 
 
    //function to upload image and check type
	
	 function upload_image($file_name) {
		   if (isset($_FILES[$file_name]))  {
		   //validate the type. Should be JPEG or PNG.
		   $allowed = array('image/pjpeg', 'image/jpeg', 'image/JPG', 'image/X-PNG', 'image/PNG', 'image/png', 'image/x-png');
		   if (in_array($_FILES[$file_name]['type'], $allowed)) {
			   return $image_type = "ok";  }
		   else 
		     { return $image_type = "error";  }
	   }
	 }  
	 //end of upload image function
							
 
 
 
    //function to reduce and move image - receives path for permanent location
     
	 function move_image($file_name, $full_path, $short_path, $image_width)  {
		 // find ext
       $ext = end( explode('.', $_FILES[$file_name]['name']) );
	  
	   //get timestamp
	   $stamp = mktime();
		
	   //set the file location
	   $new_image = $full_path.md5($_FILES[$file_name]['name']) . $stamp .'.' .$ext;
	   $stored_name = $short_path.md5($_FILES[$file_name]['name']) . $stamp .'.' .$ext;
		 
	   $original_image =  $_FILES[$file_name]['tmp_name'];
	   
	   $size = GetImageSize($original_image);	  	
	   	   
	   //default max width is 300 unless specific width passed to function   
	   $max_width = "300";
	   $max_height = "300";
	   If ($image_width) {
		   $max_width = $image_width;
		   $max_height = $image_width;}
		   	   	       
	   exec("convert -size {$size[0]}x{$size[1]} $original_image -thumbnail $max_widthx$max_height $new_image");	       
	   
	   return $stored_name;	   }
   ?>

Open in new window

0
Comment
Question by:Luey
  • 4
  • 4
9 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 40355796
If you cannot upload larger files then it's nothing to do with image magick

Check your .htaccess or php.ini file for these two settings

php_value upload_max_filesize
php_value post_max_size


...and check what they are set to

Also check if you have a max size set in the upload FORM.
0
 

Author Comment

by:Luey
ID: 40355827
Just ran phpinfo() and both are set to 10M
0
 

Author Comment

by:Luey
ID: 40355832
and nothing in htaccess about any of that.
0
 
LVL 58

Expert Comment

by:Gary
ID: 40355841
And the upload form itself?
Maybe this...
http://pivica.me/blog/500-internal-server-error-while-uploading-files-bigger-then-100kb-modfcgid-problem

Are you using a framework
0
Easy Project Management (No User Manual Required)

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 40356147
Here is my teaching example showing how to upload a file.  The man page links and comments may offer a clue.  It shows how to detect and visualize errors.

<?php // demo/upload_one_file.php
error_reporting(E_ALL);

// MANUAL REFERENCE PAGES YOU MUST UNDERSTAND TO UPLOAD FILES
// http://php.net/manual/en/features.file-upload.php
// http://php.net/manual/en/features.file-upload.common-pitfalls.php
// http://php.net/manual/en/function.move-uploaded-file.php
// http://php.net/manual/en/reserved.variables.files.php

// MANUAL PAGES THAT ARE IMPORTANT IF YOU ARE DEALING WITH LARGE FILES
// http://php.net/manual/en/ini.core.php#ini.upload-max-filesize
// http://php.net/manual/en/ini.core.php#ini.post-max-size
// http://php.net/manual/en/info.configuration.php#ini.max-input-time


// PHP 5.1+  SEE http://php.net/manual/en/function.date-default-timezone-set.php
date_default_timezone_set('America/Chicago');

// ESTABLISH THE BIGGEST FILE SIZE WE CAN ACCEPT - ABOUT 8 MB
$max_file_size = '8000000';

// ESTABLISH THE KINDS OF FILE EXTENSIONS WE CAN ACCEPT (USE UPPERCASE ONLY)
$file_exts = array
( 'JPG'
, 'PNG'
, 'GIF'
)
;
$f_exts = implode(', ', $file_exts);

// ESTABLISH THE NAME OF THE DESTINATION FOLDER
$my_dir = getcwd();

// OR USE THIS TO PUT UPLOADS IN A SEPARATE FOLDER
$my_dir = 'storage';
if (!is_dir($my_dir))
{
    mkdir($my_dir);
}

// LIST OF THE ERRORS THAT MAY BE REPORTED IN $_FILES[]["error"] (THERE IS NO #5)
$errors = array
( 0 => "Success!"
, 1 => "The uploaded file exceeds the upload_max_filesize directive in php.ini"
, 2 => "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form"
, 3 => "The uploaded file was only partially uploaded"
, 4 => "No file was uploaded"
, 5 => "UNDEFINED ERROR"
, 6 => "Missing a temporary folder"
, 7 => "Cannot write file to disk"
)
;


// IF THERE IS INFORMATION POSTED
if (!empty($_POST))
{
    // IF THERE ARE ERRORS
    $error_code    = $_FILES["userfile"]["error"];
    if ($error_code)
    {
        trigger_error($errors[$error_code], E_USER_ERROR);
    }

    // GET THE FILE SIZE
    $fsize = number_format($_FILES["userfile"]["size"]);

    // SYNTHESIZE THE NEW FILE NAME FOR TEMPORARY STORAGE
    $fname = basename($_FILES['userfile']['name']);

    // FAIL IF THIS IS NOT AN ALLOWABLE EXTENSION
    $f_ext = explode('.', $fname);
    $f_ext = end($f_ext);
    $f_ext = strtoupper(trim($f_ext));
    if (!in_array($f_ext, $file_exts)) trigger_error("$f_ext NOT ALLOWED.  CHOOSE FROM $f_exts", E_USER_ERROR);

    // THE SERVER PATH TO THE FILE
    $my_path
    = getcwd()
    . DIRECTORY_SEPARATOR
    . $my_dir
    . DIRECTORY_SEPARATOR
    . $fname
    ;

    // THE URL PATH TO THE FILE
    $my_url
    = $my_dir
    . DIRECTORY_SEPARATOR
    . $fname
    ;

    // MESSAGES ABOUT THE UPLOAD STATUS, IF ANY
    $msg = NULL;

    // IF THE FILE IS NEW (DOES NOT EXIST)
    if (!file_exists($my_path))
    {
        // IF THE MOVE FUNCTION WORKED CORRECTLY
        if (move_uploaded_file($_FILES['userfile']['tmp_name'], $my_path))
        {
            $upload_success = 1;
        }
        // IF THE MOVE FUNCTION FAILED IT PROBABLY THREW A MESSAGE
        else
        {
            $upload_success = -1;
            trigger_error("MOVE TO $my_path FAILED", E_USER_ERROR);
        }
    }

    // IF THE FILE ALREADY EXISTS
    else
    {
        $msg .= "<br/><b><i>$my_url</i></b> already exists" . PHP_EOL;

        // SHOULD WE OVERWRITE THE FILE? IF NOT
        if (empty($_POST["overwrite"]))
        {
            $upload_success = 0;
        }

        // IF WE SHOULD OVERWRITE THE FILE, TRY TO MAKE A BACKUP
        else
        {
            $now    = date('Y-m-d-His');
            $my_bak = $my_path . '.' . $now . '.bak';
            if (!copy($my_path, $my_bak))
            {
                $msg .= "<br/><strong>Attempted Backup Failed!</strong>" . PHP_EOL;
            }
            if (move_uploaded_file($_FILES['userfile']['tmp_name'], $my_path))
            {
                $upload_success = 2;
            }
            else
            {
                $upload_success = -1;
                trigger_error("MOVE TO $my_path FAILED", E_USER_ERROR);
            }
        }
    }

    // PREPARE A REPORT OF THE SCRIPT'S SUCCESS OR FAILURE
    if ($upload_success == 2) { $msg .= "<br/>A backup was made and the file was overwritten" . PHP_EOL; }
    if ($upload_success == 1) { $msg .= "<br/><strong>$my_url</strong> has been saved" . PHP_EOL; }
    if ($upload_success == 0) { $msg .= "<br/><strong>It was NOT overwritten.</strong>" . PHP_EOL; }
    if ($upload_success < 0)  { $msg .= "<br/><strong>ERROR: $my_url NOT SAVED - SEE WARNING FROM move_uploaded_file()</strong>" . PHP_EOL; }

    // ADD FILE SIZE AND PERMISSION INFORMATION
    if ($upload_success > 0)
    {
        $msg .= "<br/>$fsize bytes uploaded" . PHP_EOL;
        if (!chmod ($my_path, 0755))
        {
            $msg .= "<br/>chmod(0755) FAILED: fileperms() = ";
            $msg .= substr(sprintf('%o', fileperms($my_path)), -4);
        }
    }

    // SHOW THE SUCCESS OR FAILURE
    echo $msg;

    // SHOW A LINK TO THE FILE
    echo '<br/>'
    . '<a href="'
    . $my_url
    . '" target="_blank">'
    . "See: $my_url"
    . '</a>'
    ;
}


// CREATE THE FORM FOR INPUT (USING HEREDOC SYNTAX)
$form = <<<ENDFORM
<p>Upload one file
<form enctype="multipart/form-data" method="post">
<!-- MAX_FILE_SIZE MUST PRECEDE THE FILE INPUT FIELD -->
<input type="hidden" name="MAX_FILE_SIZE" value="$max_file_size" />
Find a file to Upload ($f_exts): <input name="userfile" type="file" />
<br/>Check this box
<input autocomplete="off" type="checkbox" name="overwrite" /> to <strong>overwrite</strong> existing files
</br><input type="submit" value="Upload" />
</form>
</p>
ENDFORM;

echo $form;

Open in new window

0
 

Author Comment

by:Luey
ID: 40356202
I am still working on your previous answers guys but I wanted you to know i get this in my error logs win it does not upload.

[Wed Oct 01 19:25:47 2014] [client 98.92.245.104] Failed loading /usr/php/54/usr/lib64/php/modules/ZendGuardLoader.so:  /usr/php/54/usr/lib64/php/modules/ZendGuardLoader.so: undefined symbol: zend_new_interned_string, referer: https://www.thecowboyshoponline.com/brand_submit.php
[Wed Oct 01 19:25:47 2014] [client 98.92.245.104] , referer: https://www.thecowboyshoponline.com/brand_submit.php
[Wed Oct 01 19:25:47 2014] [client 98.92.245.104] libgomp: Thread creation failed: Resource temporarily unavailable, referer: https://www.thecowboyshoponline.com/brand_submit.php
[Wed Oct 01 19:25:48 2014] [client 98.92.245.104] File does not exist: /home4/thecowbo/public_html/error_image.php, referer: https://www.thecowboyshoponline.com/brand_submit.php
0
 
LVL 58

Expert Comment

by:Gary
ID: 40356279
I don't know much really about Zend (bar using Magento), but maybe something in Zend was updated that changed the default file size upload limit.
0
 

Author Comment

by:Luey
ID: 40357240
This is on a shared server and I do not use any of that.  I still say this problem is at the server because I have exact same code working on other sites with the same host.  I will keep digging. Thanks
0
 
LVL 58

Expert Comment

by:Gary
ID: 40357276
Look at setting

MAGICK_THREAD_LIMIT=1
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now