file_get_contents()无法打开流:没有这样的文件或目录php

时间:2014-06-03 19:55:40

标签: php upload file-get-contents

使用这个脚本我应该可以从表单上传三个图像但是我继续file_get_contents()无法打开流:没有这样的文件或目录php我已经添加了完整路径等任何人都有任何想法?

    <?php
    ini_set('display_errors', 1);
    error_reporting(E_ALL);
    session_start();

    $full_path = $_SERVER['DOCUMENT_ROOT'];
    $folder = '/main_html/upload/';

    $upload_max_size = ini_get('upload_max_filesize');
    $post_max_filesize = ini_get('post_max_filesize');

    // boundary  
    $time = md5(time());  
    $boundary = "==Multipart_Boundary_x{$time}x"; 
    $myfile = basename($_FILES['fileupload']['name']);
    $myfile2 = basename($_FILES['fileupload2']['name']);
    $myfile3 = basename($_FILES['fileupload3']['name']);

    //echo $myfile;
    $taille_maxi = 8000 * 1024;
    $taille = filesize($_FILES['fileupload']['tmp_name']);
    $taille2 = filesize($_FILES['fileupload2']['tmp_name']);
    $taille3 = filesize($_FILES['fileupload3']['tmp_name']);
    $extensions = array('.png', '.gif', '.jpg', '.jpeg');
    $extension = strrchr($_FILES['fileupload']['name'], '.');
    $extension2 = strrchr($_FILES['fileupload2']['name'], '.');
    $extension3 = strrchr($_FILES['fileupload3']['name'], '.');
    //Début des vérifications de sécurité...
    if (!isset($_FILES['fileupload']['name']) && !in_array($extension, $extensions))//Si l'extension n'est pas dans le tableau
    {
$erreur = 'file upload1 only file type png, gif, jpg, jpeg is accepted';
    }
    if (!isset($_FILES['fileupload2']['name']) && !in_array($extension2, $extensions))//Si l'extension n'est pas dans le tableau
    {
$erreur = 'only file type png, gif, jpg, jpeg is accepted';
    }
    if (!isset($_FILES['fileupload3']['name']) && !in_array($extension3,         $extensions))//Si l'extension n'est pas dans le tableau
    {
$erreur = 'only file type png, gif, jpg, jpeg is accepted';
    }
    if ($taille > $taille_maxi) {
$erreur = 'file upload 1: file size is too big ...';
    }
    if ($taille2 > $taille_maxi) {
$erreur = 'file upload 2: file size is too big ...';
    }
    if ($taille3 > $taille_maxi) {
$erreur = 'file upload 3: file size is too big ...';
    }
    if (!isset($erreur))//S'il n'y a pas d'erreur, on upload
    {
//On formate le nom du myfile ici...
$myfile = strtr($myfile, 'ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ', 'AAAAAACEEEEIIIIOOOOOUUUUYaaaaaaceeeeiiiioooooouuuuyy');
$myfile = preg_replace('/([^.a-z0-9]+)/i', '-', $myfile);

$myfile2 = strtr($myfile2, 'ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ', 'AAAAAACEEEEIIIIOOOOOUUUUYaaaaaaceeeeiiiioooooouuuuyy');
$myfile2 = preg_replace('/([^.a-z0-9]+)/i', '-', $myfile2);

$myfile3 = strtr($myfile3, 'ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ', 'AAAAAACEEEEIIIIOOOOOUUUUYaaaaaaceeeeiiiioooooouuuuyy');
$myfile3 = preg_replace('/([^.a-z0-9]+)/i', '-', $myfile3);

if (move_uploaded_file($_FILES['fileupload']['tmp_name'], $full_path . $folder .         $myfile) || move_uploaded_file($_FILES['fileupload2']['tmp_name'], $full_path . $folder . $myfile2) || move_uploaded_file($_FILES['fileupload3']['tmp_name'], $full_path . $folder . $myfile3))  //Si la fonction renvoie TRUE, c'est que ça a fonctionné...
{

    $message = "Name: " . $_POST["name"] . "\nAddress: " . $_POST["address1"] . "\nCity: " . $_POST["city"] . "\nState: " . $_POST["state"] . "\nCountry: " . $_POST["country"];
    $message .= "\nZip : " . $_POST["zip"] . "\nHome Phone: " . $_POST["home_phone"] . "\nEmail: " . $_POST["email"];
    $message .= "\n\nEntry A Title: " . $_POST["entry_a_title"] . "\nEntry A Image Size: " . $_POST["entry_a_image_size"] . "\nEntry A Image Frame: " . $_POST["entry_a_image_frame"] . "\nEntry A Price: " . $_POST["entry_a_price"];
    $message .= "\nEntry A Filename: $myfile";
    $message .= "\n\nEntry B Title: " . $_POST["entry_b_title"] . "\nEntry B Image Size: " . $_POST["entry_b_image_size"] . "\nEntry B Image Frame: " . $_POST["entry_b_image_frame"] . "\nEntry B Price: " . $_POST["entry_b_price"];
    $message .= "\nEntry B Filename: $myfile2";
    $message .= "\n\nEntry C Title: " . $_POST["entry_c_title"] . "\nEntry C Image Size: " . $_POST["entry_c_image_size"] . "\nEntry C Image Frame: " . $_POST["entry_c_image_frame"] . "\nEntry C Price: " . $_POST["entry_c_price"];
    $message .= "\nEntry C Filename: $myfile3";
    $message .= "\n\nDelivery: " . $_POST["delivery"] . "\n ";
    $message .= "\nMembership Status: " . $_POST["Membership_status"] . "\nPayment Method: " . $_POST["Payment_Method"] . "\n\nDate: " . date("d/m/Y") . "\nTime: " . date('h:i:s A') . "\n ";

    $message .= "\n\nNOTE: If all images are not received please email";
    //$message .= "\n Form used = " . $_POST['formused'];
    //$message .= $tasktag;
    //$message .= "\n\nUploaded file 1: $myfile";
    //$message .= "\nUploaded file 1 location: $folder $myfile";
    //$message .= "\nUploaded file 2: $myfile2";
    //$message .= "\nUploaded file 2 location: $folder $myfile2";
    //$message .= "\nUploaded file 3: $myfile3";
    //$message .= "\nUploaded file 3 location: $folder $myfile3";

    //$message .= "\n\nPHP Max upload size: $upload_max_size";
    //$message .= "\n\nPHP Max post file size: $post_max_filesize";
    $message .= "\n\n$full_path";


    $boundary = "_" . md5(uniqid(rand()));

    $attached_file = file_get_contents($full_path . $folder . $myfile);
    //file name ie: ./image.jpg
    $attached_file = chunk_split(base64_encode($attached_file));

    $attached_file2 = file_get_contents($full_path . $folder . $myfile2);
    //file name ie: ./image.jpg
    $attached_file2 = chunk_split(base64_encode($attached_file2));

    $attached_file3 = file_get_contents($full_path . $folder . $myfile3);
    //file name ie: ./image.jpg
    $attached_file3 = chunk_split(base64_encode($attached_file3));

    //$attached = "\n\n". "--";

    if (file_get_contents($full_path . $folder . $myfile)) {
        $attached = "\n\n" . "--" . $boundary . "\nContent-Type: application/octet-stream; name=\"$myfile\"\r\nContent-Transfer-Encoding: base64\r\nContent-Disposition: attachment; filename=\"$myfile\"\r\n\n" . $attached_file . "--" . $boundary . "--" . "\n\n";
        $headers = "From: " . $_POST["email"] . " \r\n";
        $headers .= "MIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"$boundary\"\r\n";

        $body = "--" . $boundary . "\nContent-Type: text/plain; charset=ISO-8859-1\r\n\n" . $message . $attached;

        if ($_POST['subject'] == "National Show"){
            $email = 'email@gmail.com';
        }
        else {
            $email = 'email@gmail.com';
        }

        $subject = $_POST['name'] . " with Entry A";

        @mail($email, $subject, $body, $headers);

    }
    if (file_get_contents($full_path . $folder . $myfile2)) {
        $attached = "\n\n" . "--" . $boundary . "\nContent-Type: applicatio/octet-streamn; name=\"$myfile2\"\r\nContent-Disposition: attachment; filename=\"$myfile2\"\r\nContent-Transfer-Encoding: base64\r\n\n" . $attached_file2 . "--" . $boundary . "--" . "\n\n";

        $headers = "From: " . $_POST["email"] . " \r\n";
        $headers .= "MIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"$boundary\"\r\n";

        $body = "--" . $boundary . "\nContent-Type: text/plain; charset=ISO-8859-1\r\n\n" . $message . $attached;

        if ($_POST['subject'] == "National Show"){
            $email = 'email@gmail.com';
        }
        else {
            $email = 'email@gmail.com';
        }


        $subject = $_POST['name'] . " with Entry B";

        @mail($email, $subject, $body, $headers);
    }
    if (file_get_contents($full_path . $folder . $myfile3)) {
        $attached = "\n\n" . "--" . $boundary . "\nContent-Type: application/octet-stream; name=\"$myfile3\"\r\nContent-Transfer-Encoding: base64\r\nContent-Disposition: attachment; filename=\"$myfile3\"\r\n\n" . $attached_file3 . "--" . $boundary . "--" . "\n\n";

        $headers = "From: " . $_POST["email"] . " \r\n";
        $headers .= "MIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"$boundary\"\r\n";

        $body = "--" . $boundary . "\nContent-Type: text/plain; charset=ISO-8859-1\r\n\n" . $message . $attached;

        if ($_POST['subject'] == "National Show"){
            $email = 'email@gmail.com';
        }
        else {
            $email = 'email@gmail.com';
        }


        $subject = $_POST['name'] . " with Entry C";

        // @mail($email,$subject,$body,$headers)

    }
if (@mail($email, $subject, $body, $headers)) {
    if ($_POST['subject'] == "National Show")
        header('Location: http://www.example.org/app_2.htm');
    else
        header('Location: http://www.example.org/app_3.htm');
    //echo 'E-MAIL SEND WITH ATTACHMENT';

}
    //$attached .= "\n\n". "--" . $boundary . "--";

    //$attached .= "--" . "\n\n";

} else//Sinon (la fonction renvoie FALSE).
{
    echo 'UPLOAD ERROR !';
}
} else {
echo $erreur;
}
?>

0 个答案:

没有答案