|
 |
|
upload file เฉพาะแค่ pdf doc docx แต่มันไม่เป็นไปตามเงื่อนไขที่กำหนด ช่วยทีครับ |
|
 |
|
|
 |
 |
|
ผมจะทำการ upload file เฉพาะแค่ pdf doc docx แต่มันไม่เป็นไปตามเงื่อนไขที่กำหนด คือตอนนี้ถ้าเลือกนามสกุลไฟล์ถูกมันก็เข้า if ที่เลือกนามสกุลไฟล์ไม่ถูกครับ ผมไม่แน่ใจว่าโค้ดผมถูกมั้ย
Code (PHP)
<form name="from1" enctype="multipart/form-data" method="post" action="<?php $PHP_SELF;?>">
<table width="600" border="0" align="center">
<tr>
<td width="30%" >ICIE2015 - Send Paper</td>
<td> </td>
</tr>
<tr>
<td align="right">Paper Type</td>
<td><select name="paper_type">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
</td>
</tr>
<tr>
<td align="right">Publication Name*:</td>
<td><input type="text" name="textlimit" id="textlimit" style="width:400px" maxlength="250" value="<?php echo $_GET['data']; ?>"/></td>
</tr>
<tr>
<td> </td>
<td><div id="textlimitMAX" style="font-size:12px"></div></td>
</tr>
<tr>
<td align="right">Abstract :</td>
<td><textarea name="Wish" id="Wish" maxlength="700" style="width:400px"?><? echo $_GET['data2'];?> </textarea></td>
</tr>
<tr>
<td height="24"> </td>
<td><div id="WishMax" style="font-size:12px"></div></td>
</tr>
<tr>
<td align="right">*</td>
<td><input name="upload" type="file"><font color="#FF0000" style="font-size:12px"> *File type .doc , .docx , .pdf</font></td>
</tr>
<tr>
<td> </td>
<td><input name="up" type="submit" value="Upload"></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
</form>
<?
$pid=select("tbl_paper","order by id desc limit 1");
$paper_id = "icie2015-".$pid[paper_type]."-".($pid[id]+1);
echo $paper_id;
$dir ="C:/AppServ/www/icie/paper";
//$upload_name = iconv('UTF-8','TIS-620',$upload_name);
$path="$dir/".$upload_name;
if($up)
{
//$file = strtolower($_FILES["upload"]["name"]);
//$type= strrchr($file,".");
$data = $_POST["textlimit"];
$data2 = $_POST["Wish"];
$data3 = $_POST["paper_type"];
echo $type;
if($_POST["textlimit"] ==""){
echo"<script language='JavaScript'>";
echo"alert('Paper name not empty');";
echo"location.href='http://localhost/icie/send_paper.php?data=$data';";
echo"</script>";}
else if(empty($upload_size)){
echo"<script language='JavaScript'>";
echo"alert('Please choose file upload.');";
echo"window.location='http://localhost/icie/send_paper.php?data=$data&data2=$data2';";
echo"</script>";}
else if($_FILES['upload']['type'] != "application/pdf" || $_FILES['upload']['type'] != "application/msword" || $_FILES["upload"]["type"] == "application/vnd.openxmlformats-officedocument.wordprocessingml.document"){
echo"<script language='JavaScript'>";
echo"alert('File type not match.');";
echo"window.location='http://localhost/icie/send_paper.php?data=$data&data2=$data2';";
echo"</script>";
echo $_FILES['upload']['type'];}
else if(file_exists($path)){
echo"<script language='JavaScript'>";
echo"alert('File_exists.');";
echo"window.location='http://localhost/icie/send_paper.php?data=$data&data2=$data2';";
echo"</script>";}
else if($_FILES['upload']['type'] == "application/pdf" || $_FILES['upload']['type'] == "application/msword" || $_FILES["upload"]["type"] == "application/vnd.openxmlformats-officedocument.wordprocessingml.document"){
$sqlup = "Insert into tbl_paper(paper_id,user_id,paper_type,paper_name,paper_ab) values('$paper_id','$id',".$_POST["paper_type"]."','$upload_name','".$_POST["Wish"]."')" ;
echo $sqlup;
$objQuery = mysql_query($sqlup);
if ($objQuery){
copy($upload,$path);
echo"<script language='JavaScript'>";
echo"alert('OK.');";
echo"window.location='http://localhost/icie/send_paper.php';";
echo"</script>";
mysql_close($conn);}
}
}
?>
</body>
</html>
รบกวนพี่ๆด้วยครับ ขอบคุณมากครับ
Tag : PHP, MySQL

|
|
 |
 |
 |
 |
Date :
2014-10-07 10:14:36 |
By :
pungpoo |
View :
2813 |
Reply :
5 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
$allowedExts = array("pdf", "doc", "docx");
$extension = end(explode(".", $_FILES["upload"]["name"]));
if ((($_FILES["upload"]["type"] == "application/pdf")
|| ($_FILES["upload"]["type"] == "application/msword"))
&& ($_FILES["upload"]["size"] < 20000000)
&& in_array($extension, $allowedExts))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
}
ลองอันนี้ดูได้ไหม๊ครับ
|
 |
 |
 |
 |
Date :
2014-10-07 10:17:20 |
By :
nut_ch31 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองใช้ดูแล้วครับ ยังไม่ได้ หรือผมใช้ไม่เป็นก็ไม่รู้ T^T
|
 |
 |
 |
 |
Date :
2014-10-07 10:33:34 |
By :
pungpoo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลอง echo $extension; ดูครับว่าได้อะไร
|
 |
 |
 |
 |
Date :
2014-10-07 11:25:09 |
By :
apisitp |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
extension = end(explode(".", $_FILES["upload"]["name"]));
คำสั่งตัดตั่้งแต่จุดถึงตัวอักษรตัวสุดท้าย
|
ประวัติการแก้ไข 2014-10-07 11:57:35
 |
 |
 |
 |
Date :
2014-10-07 11:56:42 |
By :
raksaksaethao |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|