Submission with attachment PHP not working

I have a PHP script for a user to submit information from my website and include an attachment, however, if they try to upload a video, they get the status message that it failed - “Your contact request submission failed, please try again”.

Here is my code for the submit script:

    <?php
    $postData = $uploadedFile = $statusMsg = '';
    $msgClass = 'errordiv';
    if(isset($_POST['submit'])){
        // Get the submitted form data
        $postData = $_POST;
        $email = $_POST['email'];
        $name = $_POST['name'];
        $category = $_POST['category'];
    	$location=$_POST['location'];
        $URL = $_POST['URL'];
        $message = $_POST['message'];
    	$hauntname = $_POST['hauntname'];
        
        // Check whether submitted data is not empty
        if(!empty($email) && !empty($name) && !empty($message)){
            
            // Validate email
            if(filter_var($email, FILTER_VALIDATE_EMAIL) === false){
                $statusMsg = 'Please enter your valid email.';
            }else{
                $uploadStatus = 1;
                
                // Upload attachment file
                if(!empty($_FILES["attachment"]["name"])){
                    
                    // File path config
                    $targetDir = "uploads/";
                    $fileName = basename($_FILES["attachment"]["name"]);
                    $targetFilePath = $targetDir . $fileName;
                    $fileType = pathinfo($targetFilePath,PATHINFO_EXTENSION);

                     // Allow certain file formats
                    $allowTypes = array('m4p', 'mp4', 'jpg', 'png', 'jpeg', 'mov');
                    if(in_array($fileType, $allowTypes)){
                        // Upload file to the server
                        if(move_uploaded_file($_FILES["attachment"]["tmp_name"], $targetFilePath)){
                            $uploadedFile = $targetFilePath;
                        }else{
                            $uploadStatus = 0;
                            $statusMsg = "Sorry, there was an error uploading your file.\r\n";
                        }
                    }else{
                        $uploadStatus = 0;
                        $statusMsg = "Sorry, only image or video files are allowed to be uploaded.\r\n";
                    }
                
                 }
                
                if($uploadStatus == 1){
                    
                    // Recipient
                    $toEmail = '[email protected]';
                    
                    // Sender
                    $from = $email;
                    $fromName = $name;
                    
                    // Subject
                    $emailSubject = $category.' submission from '.$name;
                    
                    // Message 
                    $htmlContent = '<h2>Contact Request Submitted</h2>
                        <p><b>Name:</b> '.$name.'</p>
    					<p><b>Haunt Name:</b> '.$hauntname.'</p>
    					<p><b>Location:</b> '.$location.'</p>
                        <p><b>Email:</b> '.$email.'</p>
                        <p><b>Category:</b> '.$category.'</p>
                        <p><b>URL:</b> '.$URL.'</p>
                        <p><b>Message:</b><br/>'.$message.'</p>';
                    
                    // Header for sender info
                    $headers = "From: $fromName"." <".$from.">";

                    if(!empty($uploadedFile) && file_exists($uploadedFile)){
                        
                        // Boundary 
                        $semi_rand = md5(time()); 
                        $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; 
                        
                        // Headers for attachment 
                        $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; 
                        
                        // Multipart boundary 
                        $message = "--{$mime_boundary}\n" . "Content-Type: text/html; charset=\"UTF-8\"\n" .
                        "Content-Transfer-Encoding: 7bit\n\n" . $htmlContent . "\n\n"; 
                        
                        // Preparing attachment
                        if(is_file($uploadedFile)){
                            $message .= "--{$mime_boundary}\n";
                            $fp =    @fopen($uploadedFile,"rb");
                            $data =  @fread($fp,filesize($uploadedFile));
                            @fclose($fp);
                            $data = chunk_split(base64_encode($data));
                            $message .= "Content-Type: application/octet-stream; name=\"".basename($uploadedFile)."\"\n" . 
                            "Content-Description: ".basename($uploadedFile)."\n" .
                            "Content-Disposition: attachment;\n" . " filename=\"".basename($uploadedFile)."\"; size=".filesize($uploadedFile).";\n" . 
                            "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
                        }
                        
                        $message .= "--{$mime_boundary}--";
                        $returnpath = "-f" . $email;
                        
                        // Send email
                        $mail = mail($toEmail, $emailSubject, $message, $headers, $returnpath);
                        
                        // Delete attachment file from the server
                        @unlink($uploadedFile);
                    }else{
                         // Set content-type header for sending HTML email
                        $headers .= "\r\n". "MIME-Version: 1.0";
                        $headers .= "\r\n". "Content-type:text/html;charset=UTF-8";
                        
                        // Send email
                        $mail = mail($toEmail, $emailSubject, $htmlContent, $headers); 
                    }
                    
                    // If mail sent
                    if($mail){
                        $statusMsg = "Your contact request has been submitted successfully !\r\n";
                        $msgClass = 'succdiv';
                        
                        $postData = '';
                    }else{
                        $statusMsg = "Your contact request submission failed, please try again.\r\n";
                    }
                }
            }
        }else{
            $statusMsg = 'Please fill all the fields.';
        }
    }
    ?>

This site is live, so I need help quickly. Thank you in advance for your assistance.

The submission form itself looks like this:

<?php require_once 'submit.php'; ?>

<!DOCTYPE html>
<html lang="en-US">
<head>
<title>Home Haunter Awards Submission</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,height=device-height,initial-scale=1">

<link rel="stylesheet" href="style.css"/>
<style>
table {
    margin:0 auto;
}
a:link {
  color: green;
  background-color: transparent;
  text-decoration: none;
}
a:visited {
  color: pink;
  background-color: transparent;
  text-decoration: none;
}
a:hover {
  color: red;
  background-color: transparent;
  text-decoration: underline;
}
a:active {
  color: yellow;
  background-color: transparent;
  text-decoration: underline;
}

#link {
    display: block;
    width: 12.5em;
    padding: 0.5em;
    margin: auto;
    border: 1px solid #999;
    background-color: #000;
    box-shadow: 0.4em 0.4em 0.4em rgba( 0, 0, 0, 0.4 );
 }

#link img {
    display: block;
 }


</style>


</head>
<body>


<h1 align="center"><img border="0" src="Banner2.png" /></h1>

<table align="center" border="0" style="width: 85%">
	<tbody>
	<tr>
	<td style="width: 25%; vertical-align=top">
	<p style="text-align: center"><span style="font-size: 16px"><span style="color: #ffa500"><span style="font-family: georgia,serif"><a href="index.php">Home</a></span></span></span></p>
	</td>
	<td style="width: 25%; vertical-align=top">
	<p style="text-align: center"><span style="font-size: 16px"><span style="color: #ffa500"><span style="font-family: georgia,serif"><a href="submission.php">Submission</a></span></span></span></p>
	</td>
	<td style="width: 25%; vertical-align=top">
	<p style="text-align: center"><span style="font-size: 16px"><span style="color: #ffa500"><span style="font-family: georgia,serif"><a href="sponsor.php">Sponsor</a></span></span></span></p>
	</td>
	<td style="width: 25%; vertical-align=top">
	<p style="text-align: center"><span style="font-size: 16px"><span style="color: #ffa500"><span style="font-family: georgia,serif"><a href="contactus.php">Contact Us</a></span></span></span></p>
	</td>
	</tr>
	</tbody>
	</table>
	<br>
	<br>

<table style="height:950px; width: 85%" border="0" align="center">
	<tbody>
        <tr>
		<td width="25%"><p style="text-align: center"><strong><span style="font-size: 20px; font-weight:bold"><span style="color: #ffa500"><span style="font-family: georgia,serif">SHOW RULES</span></span></span></strong></p><br><br>
		<span style="font-size: 16px"><span style="color: #ffa500"><span style="font-family: georgia,serif">
1.	Entries will be received from now until January 22, 2020.<br><br> 
2.	Home Haunter is defined as any person(s) decorating their personal or relatives home for Halloween, either for a party, display, or walk-through, with or without scares.<br><br>
3.	Any not-for-profit home haunter may enter.  You can accept money or items for a charity donation, however you cannot make money off your haunt to be considered not-for-profit<br><br>
4.  All props must be home made either from new material or utilizing old props and refurbishing them.<br><br>
5.  URL submissions must be of a video or pic you want us to consider.  URL links to a Facebook Page or YouTube account will not be accepted.<br><br>
6.	Entries must be from home haunter’s personal props/property from 2019.<br><br>
7.	Contestants do not have to be a member of Halloween Yard Haunts and Props, but please consider joining.<br><br>
8.  Entries can be in the form of a picture or video attached in the submission email, or via a web-link (website, google drive, drop box, etc.)  directing us to the location of the picture/video.<br><br>
9.  We shouldn't have to say it, but we will.  Any props or haunts depecting nudity or graphic violence in any way will not be accepted.<br><br>
10.	Contestants can submit multiple entries to the same category as well as submit in multiple categories.<br><br>
11.	All submissions received could be used in current and future promotional campaigns.<br><br>
12.	Entries for the “Hauntcycled” category will be comprised of items not normally used for Halloween decorations, but have been hauntcycled into a prop.  Total cost of prop can only be max of $30.  If entering the “Hauntcycled” category, please make sure to describe how the prop was made, what it is made from, and how much it cost.<br><br>
13.	If you have any questions, please feel free to contact us <a href="contactus.php">here</a>.
</span></span></span></td>
		<td><div class="container">
				<div class="form-wrapper">
        		<form method="post" action="" enctype="multipart/form-data" class="animate-form">
            		<h4 class="headt" style="font-weight:bold">2019 Home Haunter Award Show Entry Form</h4>
            
            		<!-- Contact form -->
            		<div class="form-group">
                	<input type="text" name="name" class="form-control" value="<?php echo !empty($postData['name'])?$postData['name']:''; ?>" placeholder="Name" required="">
            		</div>
					<div class="form-group">
                	<input type="email" name="email" class="form-control" value="<?php echo !empty($postData['email'])?$postData['email']:''; ?>" placeholder="Email address" required="">
            		</div>
            		<div class="form-group">
                	<input type="text" name="hauntname" class="form-control" value="<?php echo !empty($postData['hauntname'])?$postData['hauntname']:''; ?>" placeholder="Haunt Name">
            		</div>
            		<div class="form-group">
                	<input type="text" name="location" class="form-control" value="<?php echo !empty($postData['location'])?$postData['location']:''; ?>" placeholder="Location" required="">
            		</div>
					<div class="form-group">
                <input list="category" name="category" class="form-control" value="<?php echo !empty($postData['category'])?$postData['category']:''; ?>" placeholder="Category" required="">
  		<datalist id="category">
			<option value="Best Static">
			<option value="Best Motorized Animatronic">
			<option value="Best Psneumatic Animatronic">
			<option value="Best Display">
			<option value="Best Walk Through">
			<option value="Best Hauntcycled">
            </div>		
            <div class="form-group">
                <input type="text" name="URL" class="form-control" value="<?php echo !empty($postData['URL'])?$postData['URL']:''; ?>" placeholder="URL">
            </div>		
            		<div class="form-group">
                	<textarea name="message" class="form-control" placeholder="Write your message here" required=""><?php echo !empty($postData['message'])?$postData['message']:''; ?></textarea>
            		</div>
            		<div class="form-group">
                	<input type="file" name="attachment" class="form-control">
            		</div>
            		<div class="submit">
                	<input type="submit" name="submit" class="btn" value="SUBMIT">
            		</div>
					<br><br>
					<!-- Display submission status -->
            		<?php if(!empty($statusMsg)){ ?>
            		<p class="statusMsg <?php echo !empty($msgClass)?$msgClass:''; ?>"><span style="color: #ffa500"><?php echo $statusMsg; ?></span></p>
            		<?php } ?>
					
        		</form>
			</div>	
		</div>
		</div>
		</td>
		<td width="25%"><p style="text-align: center"><strong><span style="color: #ffa500"><span style="font-family: georgia,serif"><span style="font-size: 20px">
		SPONSORS/LINKS</span><br><br><span style="font-size: 18px">Featured Sponsor</span></span></span></strong><br><br>
	</p>

  		<a id="link" href="#">	<img src="#" width="200" height="200" alt="" align="center"></a>
		<script src="scripts/link-rotation.js"></script>
</td>
        </tr>
    </tbody>
</table>
<div>
	
	      		
</body>
</html>

I hope this helps.

    <form id="dataEntry" action="process.php" method="post" enctype="multipart/form-data">
        <fieldset id="mainEntry">
            <legend>Journal Entry</legend>
            <div class="maxl">
                <label class="radio inline"> 
                    <input type="radio" name="page_name" value="index.php">
                    <span>Home</span> 
                </label>
                <label class="radio inline"> 
                    <input type="radio" name="page_name" value="blog.php" checked>
                    <span>Blog</span> 
                </label>
                <label class="radio inline"> 
                    <input type="radio" name="page_name" value="calendar.php">
                    <span>Calendar</span> 
                </label>                    
            </div>    

            <input type="hidden" name="user_id" value="1">
            <input type="hidden" name="action" value="enter">
            <input type="hidden" name="insert_image" value="yes">
            <input id="imgBtn" type="file" name="file">
            <select class="select-css" name="rating">
                <option value="0">Rating (Defaut: Not Rated)</option>
                <option value="1">One Star</option>
                <option value="2">Two Stars</option>
                <option value="3">Three Stars</option>
                <option value="4">Four Stars</option>
                <option value="5">Five Stars</option>
            </select>    
            <select class="select-css" name="category">
                <option value="wildlife">Wildlife</option>
                <option value="lego">LEGO</option>
                <option value="portraits-landscapes">Portraits / Landscapes</option>
                <option value="other">Other</option>
            </select>                  
            <label class="inputLabel" for="heading">Heading</label>
            <input id="heading" type="text" name="heading" value="" tabindex="1" required autofocus>
            <label class="textareaLabel" for="content">Content</label>
            <textarea id="content" name="content" tabindex="2"></textarea>
            <input type="submit" name="submit" value="enter">
        </fieldset>
    </form>

The above is a form that I use for my small CMS blog that accepts an image. Why are you putting a form inside a table? No offense, but design the table first before adding PHP to it. Even better yet use a PHP web template engine that way code will be cleaner and you can have better security as well. Anyways, back to a form with a file submission. Below is the process file that I use when I submit an entry ->

<?php

require_once '../private/initialize.php';

use Library\ProcessImage\ProcessImage as Process;
use Library\Resize\Resize;
use Library\Journal\Journal;
use Library\CMS\CMS;
use Library\Users\Users;
use Library\Read\Read;

$result = false;
$fetchUsername = new Users;
//echo $_SESSION['username'] . "<br>";
$username = $fetchUsername->username();

$journal = new Journal();
/*
 * If user is updating blog or home page.
 */
$update = filter_input(INPUT_POST, 'action', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
if (isset($update) && $update === 'update') {
    $data['id'] = filter_input(INPUT_POST, 'id', FILTER_SANITIZE_NUMBER_INT);
    $data['author'] = $username;
    $data['page_name'] = filter_input(INPUT_POST, 'page_name', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
    $data['heading'] = filter_input(INPUT_POST, 'heading', FILTER_DEFAULT);
    $data['content'] = filter_input(INPUT_POST, 'content', FILTER_DEFAULT);
    $data['rating'] = filter_input(INPUT_POST, 'rating', FILTER_SANITIZE_NUMBER_INT);
    $data['category'] = filter_input(INPUT_POST, 'category', FILTER_SANITIZE_FULL_SPECIAL_CHARS);

    $result = $journal->update($data);
    if ($result) {
        header("Location: " . $result);
        exit();
    }
}
$upload = filter_input(INPUT_POST, 'action', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
$data['user_id'] = filter_input(INPUT_POST, 'user_id', FILTER_SANITIZE_NUMBER_INT);
$data['author'] = $username;
$data['page_name'] = filter_input(INPUT_POST, 'page_name', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
$data['heading'] = filter_input(INPUT_POST, 'heading', FILTER_DEFAULT);
$data['content'] = filter_input(INPUT_POST, 'content', FILTER_DEFAULT);
$data['rating'] = filter_input(INPUT_POST, 'rating', FILTER_SANITIZE_NUMBER_INT);
$data['category'] = filter_input(INPUT_POST, 'category', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
//echo "<pre>" . print_r($data, 1). "</pre>";

if ($_FILES['file']['error'] !== 4) {
    $file = $_FILES['file']; // Assign image data to $file array:
    $thumbImage = $_FILES['file'];

    $imgObject = new Process($file, 'photos-');
    $check['image_status'] = $imgObject->processImage();
    $check['file_type'] = $imgObject->checkFileType();
    $check['file_ext'] = $imgObject->checkFileExt();


    $exif_data = exif_read_data($imgObject->saveIMG());
    if ($exif_data['Model']) {
        $data['Model'] = "Sony " . $exif_data['Model'];
        $data['ExposureTime'] = $exif_data['ExposureTime'] . "s";
        $data['Aperture'] = $exif_data['COMPUTED']['ApertureFNumber'];
        $data['ISO'] = "ISO " . $exif_data['ISOSpeedRatings'];
        $data['FocalLength'] = $exif_data['FocalLengthIn35mmFilm'] . "mm";
    }

    //echo "<pre>" . print_r($data, 1) . "</pre?";


    //echo "<pre>" . print_r($check, 1) . "</pre>\n";
    if (in_array(TRUE, $check)) {
        $errMsg = "There's something wrong with the image file!<b>";
    } else {
        $data['image_path'] = $imgObject->saveIMG();

        // *** 1)  Create a new instance of class Resize:
        $resizePic = new Resize($data['image_path']);
        // *** 2) Resize image (options: exact, portrait, landscape, auto, crop)
        $resizePic->resizeImage(2048, 1365, 'exact');
        // *** 3) Save image to directory:
        $resizePic->saveImage($data['image_path'], 100);
    }

    $thumbObject = new Process($thumbImage, 'photos-', false);
    $check['image_status'] = $thumbObject->processImage();
    $check['file_type'] = $thumbObject->checkFileType();
    $check['file_ext'] = $thumbObject->checkFileExt();
    //echo "<pre>" . print_r($check, 1) . "</pre>\n";
    if (in_array(TRUE, $check)) {
        $errMsg = "There's something wrong with the image file!<b>";
    } else {
        $data['thumb_path'] = $thumbObject->saveIMG();
        copy($data['image_path'], $data['thumb_path']);
        // *** 1)  Create a new instance of class Resize:
        $resizePic = new Resize($data['thumb_path']);
        // *** 2) Resize image (options: exact, portrait, landscape, auto, crop)
        $resizePic->resizeImage(600, 400, 'exact');
        // *** 3) Save image to directory:
        $resizePic->saveImage($data['thumb_path'], 100);
        /*
         * Save all the data from the form to the database table: cms
         */
        $result = $journal->create($data);
        if ($result) {
            header("Location: " . $result);
            exit();
        }
    }
} 

And here’s how I check and move the image (I know it’s not a video) but it should give you an idea on to . solve your problem ->

<?php

namespace Library\ProcessImage;

use PDO;
use Library\Database\Database as DB;

class ProcessImage {

    protected static $allowedExts = array("jpg", "jpeg", "gif", "png");
    protected static $allowedTypes = array("image/gif", "image/jpeg", "image/png", "image/pjpeg");
    protected $name;  // Image Name:
    public $newName = \NULL;
    protected $type;  // Image Type:
    protected $extension;   // Image Extension:	
    protected $error = \NULL; // Image Error:
    protected $size;  // Image Size:
    protected $tmpDir;
    protected $tmpName;  // Image Temporary Name:
    protected $preExt = \NULL;
    protected $thumb = 'assets/thumbnails/thumb-';
    protected $large = 'assets/large/img-';
    protected $unique = \NULL;
    protected $myDate = \NULL;
    public $username = \NULL;
    public $file = \NULL;
    public $status = \NULL;

    /*
     * 
     */

    public function __construct($file = \NULL, $username = "Strider", $picture = true) {
        //echo '<pre>' . print_r($file, 1) . "</pre>";
        $this->file = $file;
        $this->username = $username;
        if ($picture) {
            $this->preExt = $this->large;
        } else {
            $this->preExt = $this->thumb;
        }
        //echo $this->preExt . "<br>";
    }
    
    public function image($file = \NULL, $username = 'Strider', $picture = false) {
        //echo '<pre>' . print_r($file, 1) . "</pre>";
        self::__construct($file, $username, $picture);
    }

    protected function setImageExt() {
        return pathinfo($this->file['name'], PATHINFO_EXTENSION);
    }

    /*
     * Searches the contents of a file for a PHP embed tag
     * The problem with this check is that file_get_contents() reads 
     * the entire file into memory and then searches it (large, slow).
     * Using fopen/fread might have better performance on large files.
     */

    protected function file_contains_php() {
        $contents = file_get_contents($this->file['tmp_name']);
        $position = strpos($contents, '<?php');
        return $position !== false;
    }

    public function processImage() {
        $this->status = false;

        if ($this->status) {
            return $this->status; // Bad Image
        } else {
            $this->extension = $this->setImageExt(); // Set Extension if Image is valid:
            return $this->status; // Good Image
        }
    }

    public function checkFileType() {
        if (!in_array($this->file['type'], self::$allowedTypes)) {
            $this->status = TRUE; // Improper Image Type
        } else {
            $this->status = FALSE;
        }
        return $this->status;
    }

    public function checkFileExt() {
        if (!in_array($this->extension, self::$allowedExts)) {
            $this->status = TRUE; // Improper Image Extension:
        } else {
            $this->status = FALSE;
        }
        return $this->status;
    }

    public function checkFileSize() {
        $this->size = $this->file['size'];
        if ($this->size > 800000) {
            $this->status = TRUE; // Failed image size:
        }
    }

    /*
     * If image passes validation then name the file and move the image to assets/uploads
     */

    protected function uniqueName() {
        $this->myDate = new \DateTime("NOW", new \DateTimeZone("America/Detroit"));
        return $this->username . $this->myDate->format("U") . ".";
    }

    protected function getTMPName() {
        return $this->file['tmp_name'];
    }

    public function saveIMG() {
        $this->unique = $this->uniqueName();
        $this->tmpName = $this->getTMPName();
        $this->newName = strtolower($this->preExt . $this->unique . $this->extension);
        if (!$this->file['error']) {
            move_uploaded_file($this->tmpName, $this->newName);
            return $this->newName;
        }
    }

}

Lastly why did you go live until you checked out your scripts?

A video?

of what size?

Perhaps its a size limit/capacity that you are facing (as well)

Honestly, I thought I had checked all scripts before we went live, but I guess it was only with images and not video. I’ll take a look at your script and see what I can do.

I’ve tried various sizes and I still keep getting the same status message.

The error message, according to your logic, means that the mail() call failed and returned a false value. If you display/log all php errors, you will get some information that would help pin down the problem. You can also capture the last php error at that point in your logic and specifically display/log it. See the error_get_last() function.

Does the code work when no file is selected to be uploaded?

There’s a number of problems with this code. The biggest is in that it isn’t detecting if a post method form was submitted before using any of the submitted form data and it isn’t detecting if the $_POST and $_FILES arrays are not empty (occurs if the total size of the form data exceeds the post_max_size setting, which is easier to do when uploading file(s)) before referencing any of the data in them. If I/anyone has time, they will post an example showing how to properly detect a post method form submission.

Since the problem is most likely in attaching a file to the email, you would be better off by using either the phpmailer or swiftmail script and let them handle the creation of the proper email format.

Lastly, except perhaps during testing by you, these emails are NOT being sent From the email address that is being entered in the form. They are being sent from the mail server at your web hosting. The From: email address must correspond to your mail server. If no email is ever sent, with/without an attachment, this is the likely reason (when you check the php error it will be something about relaying.)

It works if an image file is attached or nothing it attached. It only fails if a video file is attached.

Is your test videos one of these formats? You are NOT allowing for CAPS in the EXTENSION names.
Perhaps your movie is tagged with a different value. How have you debugged the code? I would suggest once you get the movie’s filename, display it on the page and see if it appears valid or not. What I am saying is that movies can be named many many different extensions that you do not have listed here.
One of the most common right now is MKV format. Or test it without limits on allowed types.
This might not help, but one thing to check…

Hello Ernie,

Yes, my test video is an mp4. I actually did have CAPS in the beginning, thinking that was the problem I removed them, however it doesn’t matter if the extension is in caps or not. It still won’t allow video uploads. I did remove the limits on allowed types and it crashed the code for some reason. Nothing would attach at that point.

Good news is that I have confirmed it isn’t the code that’s the problem, it’s the mail server. I’m having someone look at my mail server to see if that is the issue or where the issue is, so fingers crossed!

Well, Joven76, step-by-step…

One thing, to remove filetype limits, you need to use * and allow ALL of them. Or, rewrite ALL of the code to not use the filetype array. Easier to just put one “*” in it.

Good luck on the mail server…

So, as it turns out, it was not my code at all, but the mail server. The max file size is messed up and that is what was causing it to fail. I’m currently working with my hosting tech support to have this resolved. Then I’ll need to go back and add the CAPS for the extensions allowed.

Thank you all to tried to help. I truly appreciate it.

No. Normalize the value by converting it to lowercase before performing the comparison.

Not familiar with Normalizing. How do I do that?

What Phdr means is you can not put the caps into the allowed array, but, instead make the incoming file’s filetype lower case. This normalizes it to the values you have in your array. In your posted code, you use this line for testing:

if(in_array($fileType, $allowTypes)){

Just change it to:

if(in_array(strtolower($fileType), $allowTypes)){

And, it will test JPG as jpg, etc…
(Normalizing is a programming term which means make the data into a more standard value.)

1 Like

Thank you for clarifying. After all the research I was doing, I was getting a little overwhelmed. This is much more simple than what I was finding online.

You are welcome. That is exactly why we are here. Glad to help.

Sponsor our Newsletter | Privacy Policy | Terms of Service