Forum

Thread tagged as: Question, Problem, Error

Crop on upload

Hello

I have a photo comp running and keep getting this error

Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 64357572 bytes) in/var/sites/s/swanagelifeboat.org.uk/public_html/perch/core/lib/PHPMailer.class.php on line 2565

i think its to do with the images sizes being too big for the email

is there a way to crop on upload ?

Thanks

Ant

Anthony Elleray

Anthony Elleray 2 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

PHP can't crop the image if it's too big to load into the available memory. You'll need to assign more memory to PHP.

Ahh ok thanks

was just in chat with hosting regarding memory increase

php is increased and error gone however

images are still being stored abouve the specified limit

is the below correct or do i need to add crop and specify size?

<perch:input type="file" id="photo1" accept="image" size="5" format="MB"/>

i uploaded 5 15mb images and the emails failed due to size i think

Debug Message
[1] SELECT * FROM perch2_members_sessions WHERE sessionID='b538181551c71ce51d24232b1de4d19a3f5d3b08' AND sessionHttpFootprint='c2ad529b65534f80670902c3bb12809f98ae644e' AND sessionExpires>'2016-08-11 17:41:37' LIMIT 1
User is logged in
[1] SELECT * FROM perch2_pages WHERE pagePath='/fundraising/lifeboat-week/upload.php' LIMIT 1
[1] SELECT * FROM perch2_shop_cart WHERE cartID=2097
[1] SELECT * FROM perch2_shop_cart WHERE cartID=2097
[42] SELECT DISTINCT settingID, settingValue FROM perch2_settings WHERE userID=0
[1] SELECT * FROM perch2_forms WHERE formKey='Photo_Comp' LIMIT 1
Building message with Dollar template
SMTP Error: data not accepted.
Using email template: /var/sites/s/swanagelifeboat.org.uk/public_html/perch/core/emails/.txt (txt)
Building message with Dollar template
SMTP Error: data not accepted.
SMTP Error: data not accepted.
INSERT INTO perch2_forms_responses(responseJSON,formID,responseIP,responseSpamData) VALUES('{\"fields\":{\"first_name\":{\"attributes\":{\"type\":\"hidden\",\"id\":\"first_name\",\"value\":\"<perch:member id=\"},\"value\":\"Anthony\"},\"last_name\":{\"attributes\":{\"type\":\"hidden\",\"id\":\"last_name\",\"value\":\"<perch:member id=\"},\"value\":\"Elleray\"},\"email\":{\"attributes\":{\"type\":\"hidden\",\"id\":\"email\",\"value\":\"<perch:member id=\"},\"value\":\"a.elleray1182@gmail.com\"},\"photo1cat\":{\"attributes\":{\"type\":\"select\",\"id\":\"photo1cat\",\"options\":\",Lifeboat, Wildlife, Landscape\"},\"value\":\"\"},\"photo2cat\":{\"attributes\":{\"type\":\"select\",\"id\":\"photo2cat\",\"options\":\",Lifeboat, Wildlife, Landscape\"},\"value\":\"\"},\"photo3cat\":{\"attributes\":{\"type\":\"select\",\"id\":\"photo3cat\",\"options\":\",Lifeboat, Wildlife, Landscape\"},\"value\":\"\"},\"photo4cat\":{\"attributes\":{\"type\":\"select\",\"id\":\"photo4cat\",\"options\":\",Lifeboat, Wildlife, Landscape\"},\"value\":\"\"},\"photo5cat\":{\"attributes\":{\"type\":\"select\",\"id\":\"photo5cat\",\"options\":\",Lifeboat, Wildlife, Landscape\"},\"value\":\"\"}},\"files\":{\"photo1\":{\"name\":\"1470933697Canon EOS 60D500.JPG\",\"path\":\"\\/var\\/sites\\/s\\/swanagelifeboat.org.uk\\/public_html\\/perch\\/resources\\/PhotoComp\\/1470933697Canon EOS 60D500.JPG\",\"size\":16270019,\"mime\":\"image\\/jpeg\",\"attributes\":{\"type\":\"file\",\"id\":\"photo1\",\"accept\":\"image\",\"size\":\"5\",\"format\":\"MB\"}},\"photo2\":{\"name\":\"14709336974199035991470933697Canon EOS 60D500.JPG\",\"path\":\"\\/var\\/sites\\/s\\/swanagelifeboat.org.uk\\/public_html\\/perch\\/resources\\/PhotoComp\\/14709336974199035991470933697Canon EOS 60D500.JPG\",\"size\":16270019,\"mime\":\"image\\/jpeg\",\"attributes\":{\"type\":\"file\",\"id\":\"photo2\",\"accept\":\"image\",\"size\":\"5\",\"format\":\"MB\"}},\"photo3\":{\"name\":\"147093369718875050101470933697Canon EOS 60D500.JPG\",\"path\":\"\\/var\\/sites\\/s\\/swanagelifeboat.org.uk\\/public_html\\/perch\\/resources\\/PhotoComp\\/147093369718875050101470933697Canon EOS 60D500.JPG\",\"size\":16270019,\"mime\":\"image\\/jpeg\",\"attributes\":{\"type\":\"file\",\"id\":\"photo3\",\"accept\":\"image\",\"size\":\"5\",\"format\":\"MB\"}},\"photo4\":{\"name\":\"1470933698Canon EOS 60D500.JPG\",\"path\":\"\\/var\\/sites\\/s\\/swanagelifeboat.org.uk\\/public_html\\/perch\\/resources\\/PhotoComp\\/1470933698Canon EOS 60D500.JPG\",\"size\":16270019,\"mime\":\"image\\/jpeg\",\"attributes\":{\"type\":\"file\",\"id\":\"photo4\",\"accept\":\"image\",\"size\":\"5\",\"format\":\"MB\"}},\"photo5\":{\"name\":\"147093369813385284421470933698Canon EOS 60D500.JPG\",\"path\":\"\\/var\\/sites\\/s\\/swanagelifeboat.org.uk\\/public_html\\/perch\\/resources\\/PhotoComp\\/147093369813385284421470933698Canon EOS 60D500.JPG\",\"size\":16270019,\"mime\":\"image\\/jpeg\",\"attributes\":{\"type\":\"file\",\"id\":\"photo5\",\"accept\":\"image\",\"size\":\"5\",\"format\":\"MB\"}}},\"page\":{\"id\":\"83\",\"title\":\"Already Registered\",\"path\":\"\\/fundraising\\/lifeboat-week\\/upload.php\",\"navtext\":\"Already Registered\"}}','8','94.192.120.84','{\"fields\":[],\"environment\":{\"CONTENT_LENGTH\":\"81351987\",\"CONTENT_TYPE\":\"multipart\\/form-data; boundary=----WebKitFormBoundarylJfCD76uyByicHNG\",\"DOCUMENT_ROOT\":\"\\/var\\/sites\\/w\\/www.swanagelifeboat.org.uk\\/public_html\",\"GATEWAY_INTERFACE\":\"CGI\\/1.1\",\"HTTP_ACCEPT\":\"text\\/html,application\\/xhtml+xml,application\\/xml;q=0.9,image\\/webp,*\\/*;q=0.8\",\"HTTP_ACCEPT_ENCODING\":\"gzip, deflate\",\"HTTP_ACCEPT_LANGUAGE\":\"en-GB,en-US;q=0.8,en;q=0.6\",\"HTTP_CACHE_CONTROL\":\"max-age=0\",\"HTTP_CONNECTION\":\"close\",\"HTTP_COOKIE\":\"p_m=b538181551c71ce51d24232b1de4d19a3f5d3b08; cmsa=1; _gat=1; PHPSESSID=229b6206c71f962241d0731acb6cfe6e; _ga=GA1.3.1874379960.1470931359\",\"HTTP_HOST\":\"www.swanagelifeboat.org.uk\",\"HTTP_ORIGIN\":\"https:\\/\\/www.swanagelifeboat.org.uk\",\"HTTP_REFERER\":\"https:\\/\\/www.swanagelifeboat.org.uk\\/fundraising\\/lifeboat-week\\/upload.php\",\"HTTP_UPGRADE_INSECURE_REQUESTS\":\"1\",\"HTTP_USER_AGENT\":\"Mozilla\\/5.0 (Windows NT 10.0; WOW64) AppleWebKit\\/537.36 (KHTML, like Gecko) Chrome\\/52.0.2743.116 Safari\\/537.36\",\"HTTP_X_FORWARDED_FOR\":\"94.192.120.84\",\"PATH\":\"\\/bin\",\"PHPRC\":\"\\/var\\/sites\\/s\\/swanagelifeboat.org.uk\\/php.ini\",\"QUERY_STRING\":\"\",\"REDIRECT_STATUS\":\"200\",\"REMOTE_ADDR\":\"94.192.120.84\",\"REMOTE_PORT\":\"48686\",\"REQUEST_METHOD\":\"POST\",\"REQUEST_URI\":\"\\/fundraising\\/lifeboat-week\\/upload.php\",\"SCRIPT_FILENAME\":\"\\/var\\/sites\\/w\\/www.swanagelifeboat.org.uk\\/public_html\\/fundraising\\/lifeboat-week\\/upload.php\",\"SCRIPT_NAME\":\"\\/fundraising\\/lifeboat-week\\/upload.php\",\"SERVER_ADDR\":\"10.168.1.130\",\"SERVER_ADMIN\":\"you@example.com\",\"SERVER_NAME\":\"www.swanagelifeboat.org.uk\",\"SERVER_PORT\":\"80\",\"SERVER_PROTOCOL\":\"HTTP\\/1.1\",\"SERVER_SIGNATURE\":\"\",\"SERVER_SOFTWARE\":\"Apache\",\"PHP_SELF\":\"\\/fundraising\\/lifeboat-week\\/upload.php\",\"REQUEST_TIME_FLOAT\":1470933603.28,\"REQUEST_TIME\":1470933603,\"argv\":[],\"argc\":0}}')
[1] SELECT * FROM perch2_forms_responses WHERE responseID='223' LIMIT 1
No ids to log.
[28] SELECT * FROM perch2_pages WHERE pageNew=0 AND pageHidden=0 ORDER BY pageTreePosition ASC
[1] SELECT pageTreePosition FROM perch2_pages WHERE pagePath='/fundraising/lifeboat-week/upload.php' LIMIT 1
[3] SELECT pageID FROM perch2_pages WHERE pageTreePosition IN ('000-006-003-004', '000-006-003', '000-006', '000') ORDER BY pageTreePosition DESC
Using template: /templates/navigation/level1.html
[3] Using template: /templates/navigation/level2.html
[4] Using template: /templates/navigation/level2.html
Using template: /templates/navigation/level2.html
[1] Using template: /templates/navigation/level3.html
[11] Using template: /templates/navigation/level3.html
[28] SELECT * FROM perch2_pages WHERE pageNew=0 AND pageHidden=0 ORDER BY pageTreePosition ASC
[1] SELECT pageTreePosition FROM perch2_pages WHERE pagePath='/fundraising/lifeboat-week/upload.php' LIMIT 1
[3] SELECT pageID FROM perch2_pages WHERE pageTreePosition IN ('000-006-003-004', '000-006-003', '000-006', '000') ORDER BY pageTreePosition DESC
Using template: /templates/navigation/off_canvas.html
[3] Using template: /templates/navigation/off_canvas_lvl1.html
[4] Using template: /templates/navigation/off_canvas_lvl1.html
[11] Using template: /templates/navigation/off_canvas_lvl1.html
[1] SELECT regionID, regionTemplate, regionPage, regionRev AS rev FROM perch2_content_regions WHERE regionKey='Title Image' AND (regionPage='/fundraising/lifeboat-week/photo-competition.php' OR regionPage='*')
[1] SELECT * FROM ( SELECT idx.itemID, c.regionID, idx.pageID, c.itemJSON, idx2.indexValue as sortval FROM perch2_content_index idx JOIN perch2_content_items c ON idx.itemID=c.itemID AND idx.itemRev=c.itemRev AND idx.regionID=c.regionID JOIN perch2_content_index idx2 ON idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev AND idx2.indexKey='_order' WHERE ((idx.regionID=162 AND idx.itemRev=1)) AND idx.itemID=idx2.itemID AND idx.itemRev=idx2.itemRev ) as tbl GROUP BY itemID, pageID, itemJSON, sortval ORDER BY sortval ASC
[1] Using template: /templates/content/title_image.html
[5] SELECT regionKey, regionHTML FROM perch2_content_regions WHERE regionPage='/fundraising/lifeboat-week/upload.php' OR regionPage='*' ORDER BY regionPage DESC
[1] SELECT pageTreePosition FROM perch2_pages WHERE pagePath='/fundraising/lifeboat-week/upload.php' OR pageSortPath='/fundraising/lifeboat-week/upload.php' LIMIT 1
[3] SELECT * FROM perch2_pages WHERE pageHidden=0 AND pageNew=0 AND pageTreePosition IN ('000-006-003-004', '000-006-003', '000-006', '000') ORDER BY pageTreePosition
[3] Using template: /templates/navigation/breadcrumbs.html
Using template: /templates/forms/photoComp.html
Using template: /templates/forms/signupForm.html

tried this and made no difference

<perch:input type="file" id="photo1" accept="image" size="5" format="MB" crop="true" width="1000" quality="60"/>

This is my form

<div class="row">
    <div class="large-12 columns">
        <div class="text-center">
            <h3>Please upload your images below</h3>
            <h4>you can submit images for one or all categories</h4>
            <p>Images must not be more than 5MB</p>
        </div>
    </div>
    <perch:form id="Photo_Comp" method="post" app="perch_forms">

        <perch:input type="hidden" id="first_name" value="<perch:member id="first_name" />" label="First Name" />
        <perch:input type="hidden" id="last_name" value="<perch:member id="last_name" />" label="Last Name" />
        <perch:input type="hidden" id="email" value="<perch:member id="email" />" label="Email" />
        <div class="large-12 columns" style="padding: 100px 0px;">
            <div class="large-2 columns">
                <perch:label for="photo1">First Image</perch:label>
                <perch:input type="file" id="photo1" accept="image" size="5" format="MB" crop="true" width="1000" quality="60"/>
                <perch:input type="select" id="photo1cat" options=",Lifeboat, Wildlife, Landscape"/>
                <perch:error for="photo1" type="fileupload">
                  <span class="error">Couldn't upload the file - could be too big.</span>
                </perch:error>
            </div>
            <div class="large-2 columns">
                <perch:label for="photo2">Seccond Image</perch:label>
                <perch:input type="file" id="photo2" accept="image" size="5" format="MB" crop="true" width="1000" quality="60"/>
                <perch:input type="select" id="photo2cat" options=",Lifeboat, Wildlife, Landscape"/>
                <perch:error for="photo2" type="fileupload">
                  <span class="error">Couldn't upload the file - could be too big.</span>
                </perch:error>
            </div>
            <div class="large-2 columns">
                <perch:label for="photo3">Third Image</perch:label>
                <perch:input type="file" id="photo3" accept="image" size="5" format="MB" crop="true" width="1000" quality="60"/>
                <perch:input type="select" id="photo3cat" options=",Lifeboat, Wildlife, Landscape"/>
                <perch:error for="photo3" type="fileupload">
                  <span class="error">Couldn't upload the file - could be too big.</span>
                </perch:error>
            </div>
            <div class="large-2 columns">
                <perch:label for="photo4">Fourth Image</perch:label>
                <perch:input type="file" id="photo4" accept="image" size="5" format="MB" crop="true" width="1000" quality="60"/>
                <perch:input type="select" id="photo4cat" options=",Lifeboat, Wildlife, Landscape"/>
                <perch:error for="photo4" type="fileupload">
                  <span class="error">Couldn't upload the file - could be too big.</span>
                </perch:error>
            </div>
            <div class="large-2 columns">
                <perch:label for="photo5">Fifth Image</perch:label>
                <perch:input type="file" id="photo5" accept="image" size="5" format="MB" crop="true" width="1000" quality="60"/>
                <perch:input type="select" id="photo5cat" options=",Lifeboat, Wildlife, Landscape"/>
                <perch:error for="photo5" type="fileupload">
                  <span class="error">Couldn't upload the file - could be too big.</span>
                </perch:error>
            </div>
            <div class="large-2 columns">
                <perch:input type="submit" id="submit-photo" value="Send" class="pay-button button"/>
            </div>
        </div>
        <perch:success>
        <div class="large-12 columns" style="padding: 100px 0px;">
            <div class="text-center">
                <h3>Thank You and good luck !!</h3>
            </div>
        </div>
        </perch:success>
    </perch:form>
</div>

and its added using

perch_form('photoComp.html');

if i upload a 15MB file (abouve the 5MB limit) and click submit i dont get the perch error display

it just uploads the file and submits

am i doing somthing wrong ?

with the power of google i found a work around

<script type="text/javascript">
$("input[id^='form1_photo']").bind('change', function() {
    //this.files[0].size gets the size of your file.
    var f = this.files[0]

    if (f.size > 5550000 || f.fileSize > 5550000)
        {
           //show an alert to the user
           alert("Allowed file size exceeded. (Max. 5 MB)")

           //reset file upload control
           this.value = null;
        }

    });
</script>