Can't upload zip files but JPEG, PNG OK

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;

}

?>

Where is the array $allowedTypes defined?

Hi

thanks for the reply, I am a total novice hence I use this script

The only reference to allowed extensions I can find is on line 96 - below

is this what you mean

many thanks

Ian

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';

As it’s a premium script, was the support no help?
http://support.bebosoft.com/forum/viewforum.php?f=2

Hi

in the past the support has been very good. But it seems to have closed down the link you gave just brings up a username and password screen.

Perhaps they have ceased trading?

cheers

Ian

Then I suggest reading up on PHP. Read up on how to make an upload system. I will be writing a blog sooner or later about this and will eventually provide hard code that works along with video and screen shots.

What happened when you entered your name and password? If that didn’t work then maybe they have closed shop.

Hi

off to read up on php

I have tried entering ,y registration detals but that doesn’t work so I think you are correct they’ve closed shop,

thanks one and all

Ian

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.