2017-02-15 78 views
-6

Move_uploaded_file無法正常工作。我嘗試了一切,但似乎沒有任何工作。move_uploaded_file無法正常工作我正在使用php 5.6.25

<?php 
 
error_reporting(E_ALL); 
 
ini_set("display_errors", 1); 
 
session_start(); 
 
error_reporting(E_ALL^E_DEPRECATED); 
 
mysql_connect("127.0.0.1","root",""); 
 
mysql_select_db("v-u-a-p"); 
 

 
if(isset($_POST['submit'])) 
 
{ 
 
\t $name = $_FILES['file']['name']; 
 
\t $temp = $_FILES['file']['tmp_name']; 
 
\t if (move_uploaded_file($temp, "/files/".$name)) { 
 
     print "Received {$_FILES['file']['name']} - its size is {$_FILES['userfile']['size']}"; 
 
    } else { 
 
     print "Upload failed!"; 
 
} 
 
\t $url="http://127.0.0.1/Number1Edward/files/$name"; 
 
\t mysql_query("INSERT INTO `videos` VALUE ('','$name','$url')"); 
 
} 
 
?> 
 
<!doctype html> 
 
<html> 
 
<head> 
 
<meta charset="utf-8"> 
 
<title>Number_1_Edward</title> 
 
<link rel="stylesheet" href="style.css?version=1"> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> 
 
<script> 
 
$(document).ready(function(){ 
 
\t $('#sidebar-btn').click(function(){ 
 
\t \t $('#sidebar').toggleClass('visable'); 
 
\t }); 
 
}); \t 
 
</script> 
 
</head> 
 
<body> 
 
<div id="box"> 
 
<center><h9 id="Logo">Number_1_Edward</h9></center> 
 
</div> 
 
<div id="sidebar"> 
 
    <ul> 
 
    <li><a href="view.php">Home</a></li> 
 
    <li><a href="upload.php">Upload</a></li> 
 
    <li><a href="register.php">Register</a></li> 
 
    <li><a href="#">About</a></li> 
 
    </ul> 
 
    <div id="sidebar-btn"> 
 
<span></span> 
 
<span></span> 
 
<span></span> 
 
</div> 
 
</div> 
 
<div id='box'> 
 
\t <h1>Videos and Photos:</h1><p>Upload your videos and photos</p> 
 
\t \t <form action="view.php" method='POST' enctype="multipart/form-data"> 
 
\t \t \t <input type="file" name="file"/> 
 
\t \t \t <input type="submit" name="submit" value="Upload!"/><br/> 
 
\t \t \t <textarea name="text" cols="40" rows="4" placeholder="Write a discription!(You must right a discription or it wont upload)" type="text"></textarea> 
 
\t \t </form> 
 
\t <?php 
 
\t if(isset($_POST['submit'])) 
 
\t { 
 
\t \t echo"<br/>".$name." has been uploaded"; 
 
\t } 
 
\t ?> 
 
\t </div> 
 
</body> 
 
</html>
該文件的所有數據上傳到mysql數據庫,但該文件是不動的,我嘗試了不同的命令,但似乎沒有任何要工作,我已經改變很多導演都times.There沒有代碼中的錯誤除了mysql被棄用,並且已經通過使用error_reporting(E_ALL^E_DEPRECATED)處理了;命令。 我正在使用一個wamp服務器和php 5.6.25。 你能幫我嗎?

+3

*「你能幫我,快答覆嗎?」 - - 截止日期吧?哎,太糟糕了。我們在這裏沒有限期;我們儘可能回答。 –

+1

對不起,我不能很快回答。但錯誤就在那裏,很容易看到。下次有禮貌。 –

+0

'並且回答很快!'但是我不能快速回答:( – Asfo

回答

0

很高興使用__DIR__來確保/files/是您認爲的。如下所示。

最有可能的答案是,它是您嘗試寫入的目錄上的權限問題,因此您可能需要獲取對您的目錄的引用,然後檢查is_writable()

$name = __DIR__.'/files/' . $_FILES['file']['name']; 
$temp = $_FILES['file']['tmp_name']; 
if (move_uploaded_file($temp, $name)) { 
    print "Received {$_FILES['file']['name']} - its size is {$_FILES['userfile']['size']}"; 
} else { 
    print "Upload failed!"; 
} 
+0

我使用了is_writable(),它表示該文件是可寫的請幫助 –

+0

@LeonardoStokes嘗試添加'print_r(error_get_last ());'在你的else塊中獲得關於錯誤的更多細節。你也可以嘗試拋棄'$ _FILES ['file'] ['error']' – Snekse