|
 |
|
อัพไฟล์ mp3 ไม่ได้ครับ ใครมีวิธีอื่นช่วยด้วยครับ มันแจ้งว่า ไม่ใช่ไฟล์ mp3 |
|
 |
|
|
 |
 |
|
Code (PHP)
<?
include("config.inc.php");
mysql_connect($host,$user,$passwd);
$sql_topic="SELECT* from open_psu where subject='$_POST[subject]' and sub_subject='$_POST[sub_subject]'";
$query_topic=mysql_db_query($dbname,$sql_topic);
$topic_list_num=mysql_num_rows($query_topic);
if($topic_list_num>0)
//die("<center>พบข้อมุลซ้อนกัน...<br />
//<a href=\"javascript: history.go(-1)\">Back</a></center>");
$filename=strtotime("now");
$filepath="../openpsu_files/";
$filepathdl="./openpsu_files/";
if($_FILES['media'] !="")
{
////////////////// Check file //////////////////////
if(($_FILES['media']['type']=="mp3") || ($_FILES['media']['type']=="mpeg"))
{
$medianame=$filename."mp3";
////////////////// Check File Exit /////////////////////
if (file_exists($filepath.$medianame)) {
$mediasts="<font color=red>The file $medianame exists.</font>";
} else {
if(copy($_FILES['media']['tmp_name'],$filepath.$medianame))
{
$mediasave=$filepathdl.$medianame;
$media_file_name=$_POST['d']."-".$_POST['m']."-".$_POST['y']."mp3";
$media_size=$_FILES['media']['size'];
$mediasts="บันทึก Media สำเร็จ";
}else{
$mediasave="";
$media_size=0;
$mediasts="บันทึก Media ไม่สำเร็จ";
}
}
}else{
$mediasts="ไฟล์นี้ไม่ใช่ mp3";
$media_size=0;
}
}else{
$mediasts="ไม่มี file Media.";
$media_size=0;
}
echo $filename;
if($_FILES['book'] !="")
{
////////////////// Check pdf file //////////////////////
if($_FILES['book']['type']=="application/pdf")
{
$pdfname=$filename.".pdf";
////////////////// Check File Exit /////////////////////
if (file_exists($filepath.$pdfname)) {
$pdfsts="The file $pdfname exists.";
} else {
if(copy($_FILES['book']['tmp_name'],$filepath.$pdfname))
{
$pdfsave=$filepathdl.$pdfname;
$book_file_name=$_POST['d']."-".$_POST['m']."-".$_POST['y'].".pdf";
$book_size=$_FILES['book']['size'];
$pdfsts="บันทึกเอกสารติวสำเร็จ";
}else{
$pdfsave="";
$book_size=0;
$pdfsts="บันทึกเอกสารไม่สำเร็จ";
}
}
}else{
$pdfsts="ไฟล์เอกสารไม่ใช่ pdf";
$book_size=0;
}
}else{
$pdfsts="ไม่มีไฟล์เอกสาร";
$book_size=0;
}
//$medianame=$filename.".mp3";
//echo $medianame;
$doa=strtotime($_POST['d'].'-'.$_POST['m'].'-'.$_POST['y']);
$nowstr=strtotime("now");
$sqlsave="INSERT into open_psu SET subject='$_POST[subject]', sub_subject='$_POST[sub_subject]', date_on_air='$doa', book_path='$pdfsave', book_file_name='$book_file_name', book_size='$book_size', media_path='$mediasave', media_file_name='$media_file_name', media_size='$media_size', date_upload='$nowstr'";
if(mysql_db_query($dbname,$sqlsave))
{
?>
<script language="javascript">
alert(" การบันทึกเสร็จสมบูรณ์แล้ว..\ : <?=$pdfsts?>\n เอกสารติว” : <?=$book_size?> Byte \n ขนาด : <?=$mediasts?> \n มิเดียไฟล์” : <?=$media_size?> Byte");
window.opener.location.reload();
window.close();
</script>
<?
}
?>
** อัพโหลด ในส่วนของ PDF ใช้ได้ครับ**
Tag : PHP, MySQL

|
ประวัติการแก้ไข 2012-02-28 22:38:41 2012-02-28 22:39:47
|
 |
 |
 |
 |
Date :
2012-02-28 22:35:47 |
By :
boycamptour |
View :
944 |
Reply :
7 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มันต้องเป็นชนิด ของไฟล์มันครับเงื่อนไข
if(($_FILES['media']['type']=="image/jpg") || ($_FILES['media']['type']=="image/jpeg"))
เคยเปิดเจออยุ่เว็บนึงที่บอกชนิดของไฟล์ แต่วิธีดูง่ายๆก้อคือ ลองอับโหลด ไฟล์ที่เป็น .mp3 แล้วลอง echo $_FILES['media']['type']; ออกมา จะได้ชนิดของไฟล์นั้นๆ
|
 |
 |
 |
 |
Date :
2012-02-28 22:38:52 |
By :
rakmomteesud |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
หาดูคำว่า mimetype ครับ
|
 |
 |
 |
 |
Date :
2012-02-28 22:44:49 |
By :
ikikkok |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
สูบ keyword หา ขนิด ไฟล์ ของพี่ PlaKriM ไปละครับ ผมหามาหลายทีละ อิอิ ^^
mp2 audio/mpeg
mp3 audio/mpeg
mp4 video/mp4
mpe video/mpeg
mpeg video/mpeg
mpg video/mpeg
if(($_FILES['media']['type']=="audio/mpeg"))
|
 |
 |
 |
 |
Date :
2012-02-28 22:53:38 |
By :
rakmomteesud |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อันที่จรังมันไม่ยากครับ ถ้าอยากรู้ว่าไฟล์นามสกุลอะไรมี minetype ว่าอะไรก็เพียง echo $_FILES['media']['type'];
|
 |
 |
 |
 |
Date :
2012-02-29 08:36:02 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มันไม่ใช่แค่นั้นนะพี่วิน เพราะบางที ie เจ้ากรรมก็ใช้ mimetype ที่ต่างจากชาวบ้านซะงั้น
|
 |
 |
 |
 |
Date :
2012-02-29 10:57:32 |
By :
ikikkok |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มันขึ้นเป็นไอ้ตัวนี้ครับ application/octet-stream
|
 |
 |
 |
 |
Date :
2012-02-29 11:56:50 |
By :
boycamptour |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้แล้วครับ ใช้ตามนี้ครับ
Code (PHP)
if($_FILES['media']['type']=="audio/mpeg" || $_FILES['media']['type']=="audio/mp3" || $_FILES['media']['type']=="application/octet-stream" )
ขอบคุณทุกท่านนะครับ
|
 |
 |
 |
 |
Date :
2012-02-29 12:27:06 |
By :
boycamptour |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 03
|