2016-08-04 58 views
2

我一直在使用我建立了很長一段時間的PHP腳本,只是最近纔有文件上傳停止工作。我沒有弄清楚什麼是錯誤的,PHP FPM文件上傳設置爲1000米,即時通訊運行在Nginx上。正確設置文件權限並使用777燙髮進行測試。PHP圖片文件上傳停止工作

這裏是我的腳本:


 

 
<?php 
 

 
    session_start(); 
 
    
 
if(!isset($_SESSION["user"]) or !is_array($_SESSION["user"]) or empty($_SESSION["user"])) { 
 
     // redirect to login page 
 
} 
 
$dbhost = "*.com"; 
 
$dbname = "*"; 
 
$dbuser = "*"; 
 
$dbpass = "*"; 
 
    
 
// database connection 
 
$conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass); 
 
// new data 
 

 

 
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]); 
 
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION); 
 

 
/* 
 
echo $target_file; 
 

 
echo $imageFileType; 
 
*/ 
 
\t \t \t \t \t $date = date('Y-m-d') ."\n"; 
 
\t \t \t \t \t $now = time(); $utc_time = $now - intval(date('Z', $now)); 
 
\t \t \t \t \t $time = date('H:i:s', $now); 
 
\t \t \t \t \t $post_id=(uniqid()); 
 
\t \t \t \t \t $MediaTxt = $_POST['MediaTxt']; 
 

 
\t \t if ($imageFileType == "jpg" || $imageFileType == "JPG") 
 
\t \t \t { 
 
\t \t \t $imageFileType = strtolower($imageFileType); 
 
\t \t \t \t \t $ip = $_POST['ip']; 
 
\t \t \t \t \t $UsrFName = $_POST['UsrFName']; 
 
\t \t \t \t \t $UsrLName = $_POST['UsrLName']; 
 
\t \t \t \t \t $UsrID = $_POST['UsrID']; 
 
\t \t \t \t \t $format = 'img'; 
 
\t \t \t \t \t $file_format = 'jpg'; 
 
\t \t \t \t \t $MediaTxt = $_POST['MediaTxt']; 
 
\t \t \t \t \t $author_id = $_POST['author_id']; 
 
\t \t \t \t \t $relation = $_POST['relation']; 
 
\t \t \t \t \t $MediaTxtNw = strip_tags($MediaTxt, '<h1><h2><h3><h4><h5><h6><img><video><audio><iframe><a>'); 
 
\t \t \t \t \t 
 
\t \t \t \t \t $tag = $MediaTxtNw; 
 
\t \t \t \t \t 
 
\t \t \t \t \t preg_match_all("/(#\w+)/", $tweet, $tags); 
 
\t \t \t \t \t 
 
\t \t \t \t \t $tweet = $MediaTxtNw; 
 
\t \t \t \t \t 
 
\t \t \t \t \t preg_match_all("/(#\w+)/", $tweet, $matches); 
 
\t \t \t \t \t 
 
\t \t \t \t \t foreach($matches[0] as $child) { 
 
\t \t \t \t \t $tags = $child . "\n" ; 
 
\t \t \t \t \t $tagsnew = preg_replace('/#([\w-]+)/i', '$1', $tags); 
 

 
\t \t \t \t \t $sql = "INSERT INTO hashtags (tag,post_id,uid,time,date) VALUES ('$tagsnew','$post_id','$UsrID','$time','$date');"; 
 
\t \t \t \t \t 
 
\t \t \t \t \t \t if ($conn->query($sql) === TRUE) { 
 
\t \t \t \t \t \t } else { 
 
\t \t \t \t \t \t } 
 
\t \t \t \t \t } 
 
\t \t \t \t \t 
 

 
\t \t \t \t \t 
 
\t \t \t \t \t $target_dir = ('../media/jpg/'); 
 
\t \t \t \t \t $target_file = $target_dir . $post_id . $author_id .'.'.pathinfo($_FILES["fileToUpload"]["name"], PATHINFO_EXTENSION); 
 
\t \t \t \t \t $uploadOk = 1; 
 
\t \t \t \t \t $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION); 
 
\t \t \t \t \t (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)); 
 

 
\t \t \t \t \t 
 
\t \t \t \t \t $sql = "INSERT INTO media (ip,date,time,firstname,lastname,userID,post_id,format,file_format,MediaTxt,author_id,relation) VALUES 
 
\t \t \t \t \t (:sasa,:sasad,:sasadf,:sasafds,:sasafda,:sasdfhj,:sasdhadka,:sasdhadkas,:sasdhadkasdas,:sashasdas,:aauutthorrid,:rrhjkjahtn)"; 
 
\t \t \t \t \t $q = $conn->prepare($sql); 
 
\t \t \t \t \t $q->execute(array(':sasa'=>$ip,':sasad'=>$date,':sasadf'=>$time,':sasafds'=>$UsrFName,':sasafda'=>$UsrLName,':sasdfhj'=>$UsrID, 
 
\t \t \t \t \t ':sasdhadka'=>$post_id,':sasdhadkas'=>$format,':sasdhadkasdas'=>$file_format,':sashasdas'=>$MediaTxtNw, 
 
\t \t \t \t \t ':aauutthorrid'=>$author_id,':rrhjkjahtn'=>$relation)); 
 
\t \t \t \t \t 
 
\t \t \t }

回答

0

嘗試通過把一些die('test');代碼在一些地方調試代碼...然後就可以看到你死代碼獲取和調試。並把這個代碼的頂部:

ini_set('display_errors', 1); 
ini_set('display_startup_errors', 1); 

error_reporting(E_ALL); 
+0

謝謝你的評論,就一定要注意:未定義的變量:TARGET_DIR在/storage/www/socialnetwk.com/home/elements/feedup.php在線23 –