I have made a version of GodfatherAntiques' image_to_contact form for ZC1.5.1, which I will soon submit as a module.
You can see it in action at here.
What I'm hoping for insight into is the handling of the "Image too large" error, which currently displays within a blank page.
All of the following code is from within the /includes/modules/pages/image_to_contact/header_php.php file.
If I understand the following code correctly it tells the program to:
For Each Uploaded File
If there is a TEMP_NAME AND the SIZE does not exceed MAX_SIZE
THEN
Upload the file to specified location
Or ELSE
IF there IS a TEMP_NAME and it's not empty
THEN
Print FILE NAME is too Large.
foreach($_FILES as $key => $file) {
if ((zen_not_null($_FILES[$key]['tmp_name'])) && ($_FILES[$key]['size'] <= MAX_FILE_UPLOAD_SIZE)) {
if ($upload = new upload($key, DIR_FS_UPLOADS)) {
$att_array[] = array('file' => $upload->destination . $upload->filename, 'name' => $upload->filename);
}
} else {
if ( zen_not_null($_FILES[$key]['tmp_name']) && ($_FILES[$key]['tmp_name'] != 'none') ) {
echo $_FILES['uploaded_file']['name']." exceeds maximum file size of ".((MAX_FILE_UPLOAD_SIZE/1024)/1000)."MB.";
}
}
What I would like to do is say,
- IF there IS a file
THEN
- IF it's NOT too large
upload it
IF it IS too large
Add this to the MESSAGE STACK
Currently the error message is printed with the above line:
echo $_FILES['uploaded_file']['name']." exceeds maximum file size of ".((MAX_FILE_UPLOAD_SIZE/1024)/1000)."MB.";
Followed by the message in this code:
//Get the uploaded file information
$name_of_uploaded_file = basename($_FILES['uploaded_file']['name']);
//get the file extension of the file
$type_of_uploaded_file = substr($name_of_uploaded_file,
strrpos($name_of_uploaded_file, '.') + 1); $size_of_uploaded_file = $_FILES["uploaded_file"]["size"]/1024;//size in KBs
$path_of_uploaded_file = $upload_folder . $name_of_uploaded_file;
$tmp_path = $_FILES["uploaded_file"]["tmp_name"];
if(is_uploaded_file($tmp_path))
{
$pic_resize = '<a href="http://www.picresize.com/" target="_newbrowser">PicResize.com</a>';
echo "Please resize large files (free resize tool available at " . $pic_resize ."), or contact us for alternate instructions.<p>
Renaissance Man Inc.<br/>
2203 N. Pace Blvd.<br/>
Pensacola, FL 32505<br/>
(850) 432-1177<br/>
[email protected]</p> <hr>";
if(!copy($tmp_path,$path_of_uploaded_file)) { $errors .= '\n error while copying the uploaded file';
echo '\n error while copying the uploaded file<hr/>';}
echo "Use browsers back button to return to contact form.";}
I am thinking I need to be working within the MESSAGE_STACK portion of the code:
else {
$error = true;
if (empty($name)) {
$messageStack->add('image_to_contact', ENTRY_EMAIL_NAME_CHECK_ERROR);
}
if ($zc_validate_email == false) {
$messageStack->add('image_to_contact', ENTRY_EMAIL_ADDRESS_CHECK_ERROR);
}
if (empty($enquiry)) {
$messageStack->add('image_to_contact', ENTRY_EMAIL_CONTENT_CHECK_ERROR);
}
}
Input is greatly appreciated.