HI
my hoster has recently upgraded to php 7. I’m creating a new site and require to upload zip files.
My knowledge of php coding is limited to say teh least so I have always used a script called formstogo.
When I use it it uploads jpegs and pngs no problem but zip files thow up an error: ( I’ve tried files from as small as 680k up to 4mb)
Errors found: Please specify a file - Incorrect file type
I know it’s a cheek but if some kind person could take a look at the code and tell me where it’s wrong I would appreciate it
thanks
Ian
<?PHP
######################################################
# #
# Forms To Go 4.5.4 #
# http://www.bebosoft.com/ #
# #
######################################################
define('kOptional', true);
define('kMandatory', false);
error_reporting(E_ERROR | E_WARNING | E_PARSE);
ini_set('track_errors', true);
function DoStripSlashes($fieldValue) {
// temporary fix for PHP6 compatibility - magic quotes deprecated in PHP6
if ( function_exists( 'get_magic_quotes_gpc' ) && get_magic_quotes_gpc() ) {
if (is_array($fieldValue) ) {
return array_map('DoStripSlashes', $fieldValue);
} else {
return trim(stripslashes($fieldValue));
}
} else {
return $fieldValue;
}
}
function FilterCChars($theString) {
return preg_replace('/[\x00-\x1F]/', '', $theString);
}
function CheckFile($theFile, $fileSize, $fileTypes, $optional) {
if ( ($theFile['size'] == 0) && ($theFile['error'] == UPLOAD_ERR_NO_FILE) && ($optional === kOptional) ) {
return 1;
}
if ( ( $theFile['error'] == UPLOAD_ERR_INI_SIZE ) || ( $theFile['error'] == UPLOAD_ERR_FORM_SIZE ) ) {
return -11;
} elseif ( $theFile['error'] == UPLOAD_ERR_PARTIAL ) {
return -12;
} elseif ( $theFile['error'] == UPLOAD_ERR_NO_FILE ) {
return -13;
} elseif ( $theFile['error'] == UPLOAD_ERR_NO_TMP_DIR ) { // Introduced in PHP 4.3.10 and PHP 5.0.3
return -14;
}
if ( is_uploaded_file( $theFile['tmp_name'] ) ) {
if ( strlen($fileTypes) > 0 ) {
$allowedTypes = explode(',', $fileTypes);
if ( !in_array($theFile['type'], $allowedTypes) ) {
return -2;
}
}
if ( $fileSize > 0 ) {
if ( $theFile['size'] > $fileSize ) {
return -1;
}
}
} else {
return -3;
}
return 1;
}
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$clientIP = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$clientIP = $_SERVER['REMOTE_ADDR'];
}
$FTGfileToUpload = $_FILES['fileToUpload']['name'];
$FTGsubmit = DoStripSlashes( $_POST['submit'] );
$validationFailed = false;
# Fields Validations
if ( ( $tmpFTGTheFileError = CheckFile($_FILES['fileToUpload'], '10000000', 'application/pdf,application/x-gzip,application/zip,image/jpeg,image/jp2,image/jpg,image/pjpeg,image/png', kOptional) ) < 0 ) {
$FTGErrorMessage['fileToUpload'] = 'Please specify a file';
$tmpFTGFileSizeErrors = array(-1, -11, -12);
if ( in_array($tmpFTGTheFileError, $tmpFTGFileSizeErrors) ) {
$FTGErrorMessage['fileToUpload'] .= ' - File size limit exceeded';
} elseif ( $tmpFTGTheFileError == -2 ) {
$FTGErrorMessage['fileToUpload'] .= ' - Incorrect file type';
} elseif ( $tmpFTGTheFileError == -12 ) {
$FTGErrorMessage['fileToUpload'] .= ' - File uploaded partially';
} elseif ( $tmpFTGTheFileError == -13 ) {
$FTGErrorMessage['fileToUpload'] .= ' - No file was uploaded';
} elseif ( $tmpFTGTheFileError == -14 ) {
$FTGErrorMessage['fileToUpload'] .= ' - Temporary directory not found';
}
$validationFailed = true;
}
# Include message in error page and dump it to the browser
if ($validationFailed === true) {
$errorPage = '<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><title>Error</title></head><body onload="window.alert('Message must be valid\n');window.alert('Message must be valid\n');">Errors found: Message must be valid</body></html>';
$errorPage = str_replace('<!--FIELDVALUE:fileToUpload-->', $FTGfileToUpload, $errorPage);
$errorPage = str_replace('<!--FIELDVALUE:submit-->', $FTGsubmit, $errorPage);
$errorPage = str_replace('<!--ERRORMSG:fileToUpload-->', $FTGErrorMessage['fileToUpload'], $errorPage);
$errorList = @implode("<br />\n", $FTGErrorMessage);
$errorPage = str_replace('Message must be valid', $errorList, $errorPage);
echo $errorPage;
}
if ( $validationFailed === false ) {
# Email to Form Owner
$emailSubject = FilterCChars("file upload");
$emailBody = "file To Upload : $FTGfileToUpload\n"
. "submit : $FTGsubmit\n"
. "";
$emailTo = 'Caoline <caroline@pcjpackaging.co.uk>';
$emailFrom = FilterCChars("enquiries@pcjpackaging.co.uk");
$emailHeader = "From: $emailFrom\n"
. "MIME-Version: 1.0\n"
. "Content-type: text/plain; charset=\"UTF-8\"\n"
. "Content-transfer-encoding: 8bit\n";
mail($emailTo, $emailSubject, $emailBody, $emailHeader);
$FTG_upload_dir = '/home/linweb39/p/pcjpackaging.co.uk-1089768579/user/htdocs/uploads';
if ( is_uploaded_file( $_FILES['fileToUpload']['tmp_name'] ) && is_writable( $FTG_upload_dir ) ) {
$FTG_filename = $_FILES['fileToUpload']['name'];
move_uploaded_file( $_FILES['fileToUpload']['tmp_name'], $FTG_upload_dir . '/' . $FTG_filename );
}
# Include message in the success page and dump it to the browser
$successPage = '<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><title>Success</title></head><body onload="window.alert('Message must be valid\n');window.alert('Message must be valid\n');">Form submitted successfully. It will be reviewed soon.</body></html>';
$successPage = str_replace('<!--FIELDVALUE:fileToUpload-->', $FTGfileToUpload, $successPage);
$successPage = str_replace('<!--FIELDVALUE:submit-->', $FTGsubmit, $successPage);
echo $successPage;
}
?>