一直困擾着網絡,很難找到獲取瀏覽文件的文件路徑的示例。其中一些人認爲由於安全原因,該功能不再適用。任何想法傢伙?我非常需要一個樣本。我已經嘗試了很多次。PHP瀏覽文件,然後得到它的路徑
這是目前我有:
<html>
<body>
<form method="post" action="file.php" enctype="multipart/form-data">
<input type="radio" name="type" value="moodle" required="required" /> Moodle<br />
<input type="radio" name="type" value="bb" required="required" /> BlackBoard<br />
<input type="file" name="file" id="file" /><br /><br />
<input type="submit" value="Submit" name="submit" />
</form>
</body>
</html>
的file.php
<?php
$filetype = $_POST["type"];
echo $filetype;
echo "Upload: " . $_FILES['file']['name'] . "<br />";
echo "Type: " . $_FILES['file']['tmp_name'];
if ($_FILES['file']['error'] > 0)
{
echo "Error: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES['file']['name'] . "<br />";
echo "Type: " . $_FILES['file']['type'] . "<br />";
echo "Size: " . ($_FILES['file']['size']/1024) . " Kb<br />";
echo "Stored in: " . $_FILES['file']['tmp_name'];
}
function moodlezip($zipfile){
echo "<h1>MOODLE</h1>"."<br />";
$moodle = new Moodle();
$zip = zip_open($zipfile);
$ziparc = new ZipArchive;
if ($zip)
{
while ($zip_entry = zip_read($zip))
{
$file = zip_entry_name($zip_entry);
//echo "Name: " . $file . "<br />";
if (strpos($file,'course.xml') !== false) {
if ($ziparc->open($zipfile) === TRUE) {
$coursexml = new SimpleXMLElement($ziparc->getFromName($file));
$moodle->getCourse($coursexml);
$ziparc->close();
} else {
echo 'failed';
}
}
else if (strpos($file,'forum.xml') !== false) {
if ($ziparc->open($zipfile) === TRUE) {
$topicxml = new SimpleXMLElement($ziparc->getFromName($file));
$moodle->getTopic($topicxml);
$ziparc->close();
} else {
echo 'failed';
}
}
else if (strpos($file,'lesson.xml') !== false) {
if ($ziparc->open($zipfile) === TRUE) {
$lessonxml = new SimpleXMLElement($ziparc->getFromName($file));
$moodle->getLessons($lessonxml);
$ziparc->close();
} else {
echo 'failed';
}
}
else if (strpos($file,'quiz.xml') !== false) {
if ($ziparc->open($zipfile) === TRUE) {
$quizxml = new SimpleXMLElement($ziparc->getFromName($file));
$moodle->getQuizzes($quizxml);
$ziparc->close();
} else {
echo 'failed';
}
}
else if (strpos($file,'questions.xml') !== false) {
if ($ziparc->open($zipfile) === TRUE) {
$questionsxml = new SimpleXMLElement($ziparc->getFromName($file));
$moodle->getQuestions($questionsxml);
$ziparc->close();
} else {
echo 'failed';
}
}
}
zip_close($zip);
}
}
require_once 'classes/backup.php';
$connect = mysql_connect("localhost","root","");
if (!$connect)
{
die('Could not connect: ' . mysql_error());
}
mysql_close($connect);
//form upload loop folders input submit, find, bb, scorm
//class admin
?>
我認爲你需要提供一個你正在嘗試做的例子,它不是很清楚。 – 2012-08-14 15:24:52
「瀏覽文件」是什麼意思?該文件在*服務器*還是*客戶端*上?如果文件來自客戶端,那麼您**無法獲取其路徑。 – 2012-08-14 15:25:02
[從瀏覽器獲取上傳文件夾和文件名](http://stackoverflow.com/questions/6660094/get-upload-folder-and-filename-from-browser)(和[很多很多人](http ://stackoverflow.com/search?q = fakepath + get + real + path + of + file + on + client)) – Quentin 2012-08-14 15:25:15