联系表单和上传文件表单之间的交叉

I'm working on a file upload form that I would like to do 3 specific things. Maybe it's late and I'm an amateur coder so I'm having trouble wrapping my head around what needs to be done here.

  • I need help making the upload form email me when a file is uploaded, nothing fancy.
  • I need help making the uploaded file make a new directory of www.mywebsite.com/uploads/$client. (which will be filled in in the form)
  • I need help making sure the form has the required information filled out before being ready to submit (email, name, file chosen).

Here is the code I have so far:

 <?php 
$name = $_FILES['file']['name'];    
$extension = strtolower(substr($name, strpos($name, '.') + 1));
$type = $_FILES['file']['type'];
$tmp_name = $_FILES['file']['tmp_name'];
$size = $_FILES['file']['size'];
$max_file_size = 34000000;
$client = $_POST['client'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name 
 Message: $message";
$recipient = "test@test.com";
$subject = "File upload from:";
$mailheader = "From:" . $email;


    if (isset($name)) {
    if (!empty($name)) {

        if (($size<=$max_file_size)) {

        $location = '../uploads/';
            if (move_uploaded_file($tmp_name, $location.$name)); {
                echo 'File uploaded :)';
            }
        } else {
            echo('File type not accepted.  File size must be 30mb or less.');
        }
    } else {
        echo('Please choose a file before hitting submit');
    }
    }

    ?>

I thank you all for any help you may offer!

PHP email - http://php.net/manual/en/function.mail.php

PHP create directory - http://php.net/mkdir

jquery form validation - http://jqueryvalidation.org/documentation/

These Google searches are killing me :P

It will be a very long answer to the questions. I'll try to give some short but useful hints.

  1. Sending mail you can use mail function but bad things can happen like it may be marked as spam by your mail provider.
  2. Making new directory you can use mkdir function. You can check if the directory exists before mkdir.
  3. Form validation you need to learn javascript, and maybe jQuery, or make use of some javascript form validation framework.
<?php
$max_file_size = 34000000;
$client = $_POST['client'];
$email = $_POST['email'];
$message = $_POST['message'];
if($client!='' && $email!=''){
    $filename = stripslashes($_FILES['file']['name']);
    if($filename!=''){
        $size=filesize($_FILES['file']['size']);
        $extension = getExtension($filename);
        $extension = strtolower($extension);
        if($extension=="jpg" || $extension=="jpeg" || $extension=="png" ){
            if( $size <= $file_size_limit){
            move_uploaded_file($_FILES["file"]["name"],"upload/" .date("d_m_h_i_s"). $_FILES["file"]["name"]);
            }else {
                echo 'Max File Uplode size Error';
            }
        } else{
         echo 'Invalid File Type';
        }
    } else {
    echo 'Please insert a file';
    }
} else {
 echo 'Please enter the details';
}


function getExtension($str){
    $i = strrpos($str,".")
    if (!$i){
        return "";
    }
    $l = strlen($str) - $i;
    $ext = substr($str,$i+1,$l);
    return $ext;
}
?>

i haven't tested it . you need to now use the details in mail function. The files are checked based on extention & size. I hope you are using method as POST & enctype="multipart/form-data" for form upload. Try using email validation using JS also