0

だから私はすでにそこにあったいくつかのコードを編集しています.PDF以外のファイルをアップロードできるように追加の拡張機能を追加する方法がわかりません.手がかりはありますか? jpeg、docx、doc、xls、wpsを追加したいです。

<?php

$lastname=$_POST['mylastname'];

$firstname=$_POST['myfirstname'];

$asuid=$_POST['#'];

$ftype=$_POST['ftype'];

$dkServerConn = mysql_connect("#", "#", "#") or die("no way");
mysql_select_db("#", $dkServerConn) or die("Cannot connect to the DB!");



$sql1 = "SELECT * FROM scholnumber";
$dkResultSet1 = mysql_query($sql1,$dkServerConn) or die(mysql_error());
$checkIt=0;

 while ($dkROWrecord1 = mysql_fetch_array($dkResultSet1,MYSQL_BOTH))


{
$checkIt=$dkROWrecord1['filenumber'];
}

$checkIt2=$checkIt+1;


$sql2="Update scholnumber set filenumber='".$checkIt2."'";
$dkResultSet2 = mysql_query($sql2,$dkServerConn) or die(mysql_error());


echo "<html>
        <head>
            <title>Uploading Information</title>
                <style> body { font-family:arial; font-size:14px } </style>
        </head>
            <body><table cellpadding='5' align='center' width='55%'><tr><td><p>&nbsp;</p>
                <img src='#'><br />
                <img src='#'><br />
        <span style='font-family:arial;font-size:14pt'>&nbsp; &nbsp; &nbsp; 2013-2014 Privately Funded Scholarship Application</span>
            <h3><br/>";


// File validation -->

$allowedExts = array("pdf","docx","doc","wps");

$extension = end(explode(".", $_FILES["file"]["name"]));


if (($_FILES["file"]["type"] == "application/pdf")
&& in_array($extension, $allowedExts)){
    if ($_FILES["file"]["error"] > 0){
        echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
    }
    else{
        echo "<p />Submission successful.<p />

    Your submission has been received. If you have loaded all of your documents, you can close this browser. Your scholarship application is complete.<p />";

        echo "Upload: " . $_FILES["file"]["name"] . "<br>";
        echo "Type: " . $_FILES["file"]["type"] . "<br>";


        if (file_exists("upload/" . $_FILES["file"]["name"])){
            echo $_FILES["file"]["name"] . " already exists. ";
        }
        else{
            $ext = substr($_FILES['file']['name'], strpos($_FILES['file']['name'],'.'), strlen($_FILES['file']['name'])-1);     
            $docName = $checkIt.$ext;
            move_uploaded_file($_FILES["file"]["tmp_name"],"upload/" . $docName);
            // echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
        }
    }
}
elseif($_FILES["file"]["type"] == "application/pdf"){

}
else{
echo "<hr>  <p /> >>>>>>  INVALID FILE <<<<<<<< <p />&nbsp;<p />";  
}

// End of the validation


$sql3="insert into scholfile (filename, lastname, firstname, asuid, ftype) values ('$checkIt', '$lastname', '$firstname', '$asuid', '$ftype')";
$dkResultSet3 = mysql_query($sql3,$dkServerConn) or die(mysql_error());


$sql6="select * from scholarships where asuid='".$asuid."'";
$dkResultSet6 = mysql_query($sql6,$dkServerConn) or die(mysql_error());


 while ($dkROWrecord6 = mysql_fetch_array($dkResultSet6,MYSQL_BOTH))
           {
            $email=$dkROWrecord6['email'];
           }

$from="Scholarships";
$fromem="scholarships@#.edu";


$subjectStudent = "Thank you for your supporting documentation.";
$messageStudent="Hello, ".$firstname. " -<p />

We have received your ".$ftype.". <p /> 

<hr />

If you have any questions, please contact the Financial Aid and Scholarships Office at 870-972-2310 or reply to this email. 
<p />

Thank you for your submission.<br />Financial Aid and Scholarships Office";


//Email Information

$headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "To:" .$firstname. "<" . $email. ">\r\n";
$headers .= "From:" . $from . "<". $fromem . ">\r\n";



mail($email, $subjectStudent, $messageStudent, $headers);

?> 

<p />&nbsp; <p />
If you have another document to submit, please <a href='fileupload.php'>click here.</a><p />

Thank you!<p /></body></html>
4

2 に答える 2

1

私はまだこれを自分で行っていないので、私の答えが正しいかどうかはわかりませんが、ここで試してみてください. (未テスト)

あなたのコードは、ここでドキュメントをアップロードするためのファイルの種類を制限します:

if (($_FILES["file"]["type"] == "application/pdf") && in_array($extension, $allowedExts)){

コードのファイル検証部分を次のように変更します。

// File validation -->

$allowedExts = array("pdf","docx","doc","wps","jpg"); //Added jpg

//Get Filename Extension into var (your code - unchanged)
$extension = end(explode(".", $_FILES["file"]["name"]));

//Create array of acceptable file types:
// Sources:  (1) http://filext.com/file-extension/DOC and (2) http://php.net/manual/en/function.mime-content-type.php
$doctype = array("application/msword","application/doc","appl/text","application/vnd.msword","application/vnd.ms-word","application/winword","application/word","application/x-msw6","application/x-msword");
$xltype = array("application/vnd.ms-excel","application/msexcel","application/x-msexcel","application/x-ms-excel","application/vnd.ms-excel","application/x-excel","application/x-dos_ms_excel","application/xls");
$jpgtype = array("image/jpeg","image/jpg","image/jp_","application/jpg","application/x-jpg","image/pjpeg","image/pipeg","image/vnd.swiftview-jpeg","image/x-xbitmap");
$wpstype = array("application/vnd.ms-works","application/x-msworks-wp","zz-application/zz-winassoc-wps","text/plain");
//Combine them into one array:
$allowedFT = array_merge($doctype, $xltype, $jpgtype, $wpstype);

//Get this file's file type into var
$ft = $_FILES["file"]["type"];

//NOW DO THE BIG TEST
if (in_array($ft, $allowedFT) && in_array($extension, $allowedExts)){
于 2013-10-10T19:54:20.337 に答える