Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/251.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php file_get_contents()无法打开流:没有这样的文件或目录_Php_Upload_File Get Contents - Fatal编程技术网

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

Php file_get_contents()无法打开流:没有这样的文件或目录,php,upload,file-get-contents,Php,Upload,File Get Contents,有了这个脚本,我应该能够从一个表单上传三个图像,但是我继续文件。\u get\u内容无法打开流:没有这样的文件或目录php我已经添加了完整的路径等。有人有什么想法吗 <?php ini_set('display_errors', 1); error_reporting(E_ALL); session_start(); $full_path = $_SERVER['DOCUMENT_ROOT']; $folder = '/main_html/

有了这个脚本,我应该能够从一个表单上传三个图像,但是我继续文件。\u get\u内容无法打开流:没有这样的文件或目录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;
}
?>

$full_path的值是多少$文件夹$myfile和类似的字符串连接?您是否进行了4次调试以确定这些值是您所期望的值,并且文件确实位于您所期望的位置?请尝试打印$full_path并查看它是否确实存在。如果是,请尝试更改$full_path目录的权限。chmod xxx dir这通常是权限chmod或用户权限chown。@MikeBrant它在htdocs+文件名处打印doc root+路径的完整路径。Nu Gnoj Mik,Kohjah Breese上传目录的权限设置为755。经过一些测试,似乎我无法上传大于400KB的文件,即使我的上传大小和最大上传设置为20M