我問了類似的問題yestarday,但沒有得到任何迴應,這將幫助我,我想要做的是 1.上傳文件到服務器 2.get文件的名稱所以如果它是'hope.jpg'文件並被上傳到一個名爲'uploads'的文件夾中,那麼稍後我需要'uploads/hope.jpg'。上傳文件傳遞名稱的PHP問題
我試圖把它作爲變量的工作不顯示這樣的信息:
有上傳文件時發生錯誤,請重試! 警告:fopen(uploads /)[function.fopen]:未能打開流:權限被拒絕D:\ www \ 2010-msc \ businesscards \ QRCodeAPI.class.php在線112
警告:curl_setopt :在第121行D:\ www \ 2010-msc \ businesscards \ QRCodeAPI.class.php中提供的參數不是有效的文件句柄資源
警告:fclose():提供的參數不是有效的流資源d:\ WWW \ 2010-MSC \ businesscards \ QRCodeAPI.class.php在譯碼器線130 錯誤:
這裏是我使用的HTML表單:
<form enctype="multipart/form-data" action="index.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>
<form action="<?php echo $_SERVER["SCRIPT_NAME"]; ?>" method="POST">
<label for="action"> Method:</label>
<select id="action" name="action">
<option value="generate" <?php echo $action == "generate" ? 'selected="selected"' : ""; ?>>generate</option>
<option value="encode" <?php echo $action == "encode" ? 'selected="selected"' : ""; ?>>encode</option>
<option value="decode" <?php echo $action == "decode" ? 'selected="selected"' : ""; ?>>decode</option>
</select>
</br>
<label for="message">Message:</label>
<input type="text" id="message" name="message" value="<?php echo $message; ?>" />
<input type="submit" value="Submit" />
</form>
然後我上傳一個這樣的文件:
// Where the file is going to be placed
$target_path = "uploads/";
/* Add the original filename to our target path.
Result is "uploads/filename.extension" */
$target_path = $target_path . basename($_FILES['uploadedfile']['name']);
$a = basename($_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path))
{
echo "uploads/". $a;
} else{
echo "There was an error uploading the file, please try again!";
}
和文件上傳後,我試圖解碼與
$json = $api->decode ("uploads/". $a);
$start='{"content":"';
$pos_start = strpos($json, $start);
$end='"}';
$pos_end = strpos($json, $end);
if ($pos_start === false || $pos_end === false)
{
echo "error in decode";
exit();
}
$wiadomosc = substr($json,12,$pos_end - 12);
echo $wiadomosc;
exit();
break;
不幸的是,線$json = $api->decode ("uploads/". $a);
帶來的只是一些錯誤,但如果你手動寫入服務器上的文件名稱,如$json = $api->decode ("uploads/hope.jpg");
,一切正常。你能給我任何關於如何獲取文件名稱的建議,就好像它是手動輸入一樣cuz顯然它不工作,當我把變量,而不是!感謝所有迴應
不,但thax已經解決了問題 – anna