[請益] 無法正確抓到_POST的值?
因為是新手+非科班,所以寫的不好code很亂請多包涵...>"<
現在的問題是這個code我在自己的電腦主機做測試時是OK的
換到學校的server上就不行了
一直出現像這樣
"Notice: Undefined index: uploadfile in
/..../php_ffmpeg.php on line 51 Notice: Undefined index:
uploadfile in /..../php_ffmpeg.php on line 57..."
google了一下解決方式
有一種是改php.ini的設定 但好像不是很推
所以我有試一下另一種用if(isset())去寫的方式
就像下面20111114.edit~20111114.edit.end的範圍....
-------------------
<?php
ini_set('display_errors','On');
set_time_limit(500);
include_once("connect_db.php");
//20111114.edit
//檢查是否有輸入檔名
if(isset($_POST["file_name"])){
if($_POST["file_name"] == null){
die('Please input the file name.');
};
};
//檢查有沒有選取檔案
if(isset($_FILES["uploadfile"]["name"])){
if($_FILES["uploadfile"]["name"] == null){
die('Please choose one file.');}
};
//檢查檔案是否已存在
if(isset($_POST["file_name"])){
$query = "SELECT * FROM `ffmpeg_upload_video` WHERE `file_name` =
'$_POST[file_name]'";
$result = mysql_query($query,$con) or die("Can't send your query".
mysql_error());
$num_rows = mysql_num_rows($result);
if ($num_rows > 0){
die("The file has already existed!");
};
};
//20111114.edit.end
-----
但是下面這一段開始就是即使補了if(isset())的寫法進去
也還是失敗....
但相當奇妙的是其他的頁面都可以抓到表單傳來的值(比如留言和msg的功能)
在這個的form其實裡面只有
file_name
description
uploadfile
這三個欄位而已 所以不知道到底是哪裡錯了...
還請好心的高手幫忙回答一下...
--------
//定義路徑
$myURL = "http://localhost/";
//檔案保存的初期設定
//檔案保存的directory
$inputFile_path = 'video_upload/';
//存檔檔名
if ($_FILES["uploadfile"]["error"] > 0)
{
echo "Error: " . $_FILES["uploadfile"]["error"] . "<br />";
}
else
{
$file_path = $inputFile_path . $_FILES["uploadfile"]["name"];
}
//ffmpeg初期設定
//ffmpeg的位置
$ffmpeg_path = '.\\3GP_Converter034\\cores\\ffmpeg';
//轉檔後的檔案位置
$outputFile_dir = 'video_upload\\';
//轉檔後的檔名
//$outputFile_name = $_FILES["uploadfile"]["name"].'_.mp4';
$outputFile_name = $_POST["file_name"]/*["file_name"]*/.'_.mp4';
$outputFile_path = $outputFile_dir . $outputFile_name;
$outputFile_path2 = 'video_upload/' . $outputFile_name;
//轉換選項之1
$command_option1 = ' -y -i ';
//轉換選項之2
$command_option2 = ' -f mp4 -vcodec h264 -r 25 -b 1200k -s 640x480 -acodec
mp3 -ar 44100 -ab 64k ';
//播放器的初期設定
$thumbFile_name = $_FILES["uploadfile"]["name"].'_.jpg';
$thumbFile_path = $outputFile_dir. $thumbFile_name;
$thumbFile_path2 = 'video_upload/'. $thumbFile_name;
//播放器選項之2
$thumbFile_option2 = ' -f image2 -s 320x240 -ss 3 -r 1 -t 0:0:0.001 -an ';
//取得已上傳之檔案
if(move_uploaded_file($_FILES["uploadfile"]["tmp_name"], $file_path)){
//取得移動之檔案
chmod($file_path,0644);
//指定pass
$video_dir = 'video_upload\\';
$video_path = $video_dir. $_FILES["uploadfile"]["name"];
//轉換成FLV
//轉換的script
$command_line_video = $ffmpeg_path . $command_option1 . $video_path .
$command_option2 . $outputFile_path;
//實行變換FLV的command
$last_line_video = system($command_line_video, $retval_video);
/*
echo '<script type = "text/javascript" src="'. $myURL .
'ffmpeg.js"></script>';
echo '<script language="javascript">foutput("'.$myURL . '","'.
$outputFile_name.'");</script>';*/
//生成播放器
//生成播放器的指令
$command_line_img = $ffmpeg_path . $command_option1 . $outputFile_path .
$thumbFile_option2 . $thumbFile_path;
//實行播放器生成的command
$last_line_img = system($command_line_img, $retval_img);
//echo '<p><img src="'. $myURL . $tumbFile_path . '"/></p>';
//echo '<video width="320" height="240" src="'.$outputFile_path2.'"
controls></video>';
//echo '<video width="320" height="240" src="text.mp4" controls ></video>';
}
if(is_uploaded_file($file_path))
{
copy($file_path,$outputFile_path2);
unlink($file_path);//刪除上傳檔案(暫存位置)
}
date_default_timezone_set('Asia/Tokyo');
$datetime = date("Y-m-d H:i:s");
$id = $_SESSION['id'];
$sql=<<<eof
INSERT INTO `ffmpeg_upload_video`(file_name, video_path, thumb_path,
description, submit_user, created)
VALUES
('{$_POST["file_name"]}','{$outputFile_path2}','{$thumbFile_path2}','{$_POST["description"]}','{$id}','{$datetime}');
eof;
/*if(!$result = mysql_query($sql,$link))
{
echo("Sorry!can't deal with the file now!\n");
exit();
}*/
$rst=mysql_query($sql, $con);
if($rst){
//if success
print "Your video has been saved! <br>";
}
else{
//if fail
print "failed...<br>";
echo mysql_errno($con) . ": " . mysql_error($con). "\n";
echo mysql_errno($con) . ": " . mysql_error($con) . "\n";
}
$con=mysql_close($con);
?>
---------------------------------------------
才疏學淺 真的很不好意思
拜託大家了~
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 219.167.255.64
※ 編輯: yoshihito 來自: 219.167.255.64 (11/14 04:10)
→
11/14 04:21, , 1F
11/14 04:21, 1F
→
11/14 04:22, , 2F
11/14 04:22, 2F
→
11/14 04:22, , 3F
11/14 04:22, 3F
→
11/14 04:23, , 4F
11/14 04:23, 4F
→
11/14 04:29, , 5F
11/14 04:29, 5F
→
11/14 06:36, , 6F
11/14 06:36, 6F
→
11/14 12:39, , 7F
11/14 12:39, 7F
→
11/14 13:08, , 8F
11/14 13:08, 8F
→
11/14 16:46, , 9F
11/14 16:46, 9F
※ 編輯: yoshihito 來自: 131.113.137.195 (11/14 21:24)
→
11/14 21:29, , 10F
11/14 21:29, 10F
→
11/14 21:30, , 11F
11/14 21:30, 11F
→
11/14 21:31, , 12F
11/14 21:31, 12F
→
11/14 21:31, , 13F
11/14 21:31, 13F
PHP 近期熱門文章
PTT數位生活區 即時熱門文章