1
我有一個頁面上有兩種形式,應該給用戶posibility加載文件到服務器(從網址或從用戶的PC)加載文件到服務器
<form method="post" action="bigorder.php" name="photourl">
<label for="photoorig">URL</label>
<input type="url" name="photoorig" placeholder="">
<input type="submit" value="Load" name="photoload">
<br>
</form>
<form method="post" action="bigorder.php" name="photofile" enctype="multipart/form-data">
<label for="photoloc">Load own file</label>
<input type="file" name="photoloc" id="photoloc">
<input type="submit" value="Load" name="photoload2">
</form>
和PHP
<?php
$tmpname=rand().".jpg";
if ($_POST['photoorig']) {
$file=file_get_contents($_POST['photoorig']);
$fp = fopen("/var/www/html/uploads/tmp/".$tmpname, "w");
fwrite($fp, $file);
fclose($fp);
}
if ($_POST['photoloc']) {
$tmpFile = $_FILES['photoloc']['tmp_name'];
$newFile = "/var/www/html/uploads/tmp/".$_FILES['photoloc']['name'];
$result = move_upload_file($tmpFile, $newFile);
echo $_FILES['photoloc']['name'];
if ($result) {
echo ' was uploaded<br />';
} else {
echo ' failed to upload<br />';
}
?>
第一種形式加載文件很好,但第二個完全不起作用。我甚至沒有收到任何錯誤信息。
我在做什麼錯?或缺少什麼?
使用的功能是'move_uploaded_file()以',不'move_upload_file()' – D4V1D 2015-03-25 10:56:25
另外,如果沒有輸出,也許是因爲病情'如果($ _ POST [ 'photoloc'])'是永遠見過面嗎? – D4V1D 2015-03-25 10:57:33
@ D4V1D,謝謝!改變右邊的'move_uploaded_file()'有助於解決問題! – Anatoly 2015-03-25 12:18:26