2015-08-14 21 views
0

我怎麼會返回true或false,上傳文件匹配FULL_WRITTEN_MONTH和YEAR.txt或.csvPHP的preg_match一個文件名MONTHYEAR.txt或.csv和返回true或false上載

例子:

JANUARY2015.txt

MARCH2016.csv

DECEMBER2017.txt

將驗證爲真。

december2013 =假

dec2013 =假

2013年12月=假

if($_SERVER['REQUEST_METHOD'] == 'POST') { 

$target_dir = "uploads/"; 

$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); 

$uploadOk = 1; 

$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION); 

// Check if image file is a actual image or fake image 
if(isset($_POST["submit"])) { 
$check = filesize($_FILES["fileToUpload"]["tmp_name"]); 
if($check !== false) { 
    echo "File is an file - " . $check["mime"] . "."; 
    $uploadOk = 1; 
} else { 
    echo "File is not a file."; 
    $uploadOk = 0; 
} 
} 
// Check if file already exists 
if (file_exists($target_file)) { 
echo "Sorry, file already exists."; 
$uploadOk = 0; 
} 
// Check file size 
if ($_FILES["fileToUpload"]["size"] > 500000) { 
echo "Sorry, your file is too large."; 
$uploadOk = 0; 
} 
// Allow certain file formats 
if($imageFileType != "txt" || $imageFileType != "csv") { 
echo "Sorry, only TXT CSV files are allowed."; 
$uploadOk = 0; 
} 
// Check if $uploadOk is set to 0 by an error 
if ($uploadOk == 0) { 
echo "Sorry, your file was not uploaded."; 
// if everything is ok, try to upload file 
} else { 
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) { 
    echo "The file ". basename($_FILES["fileToUpload"]["name"]). " has been uploaded."; 
} else { 
    echo "Sorry, there was an error uploading your file."; 
} 

}

回答

0

爲了讓你開始:

<?php 

$a = 'DECEMBER2015'; 
$b = 'december2015'; 

foreach (array('DECEMBER') as $month) 
{ 
    var_dump($month.'2015' == $a); //true 
    var_dump($month.'2015' == $b); //false 
} 

?> 

讓2升例如,興奮劑的年齡和月份範圍。