所以我在PHP這個代碼,需要一個形式的結果:失敗通過PHP上傳圖像服務器
<?php if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
{
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
$path = $_SERVER['DOCUMENT_ROOT'] . "/uploads/";
//$path = "uploads/";
$path = $path . basename($_FILES['userfile']['name']);
is_uploaded_file($_FILES['userfile']['tmp_name']) or error('not an HTTP upload');
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $path))
{
echo "The file ". basename($_FILES['userfile']['name']) . " has been uploaded, and your information has been added to the directory";
}
else
{
echo "Sorry, there was a problem uploading your file -->" . $path;
}
} ?>
我的問題是,代碼經過is_uploaded_file
但在執行move_uploaded_file
此代碼是我在許多php論壇和教程中找到的代碼。
任何人都知道爲什麼它不會上傳到我的服務器上。
編輯:
下面是用HTML代碼完整PHP文件:
<!DOCTYPE html>
<html>
<head>
<title>Montréal Accessible</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="vendors/bootstrap/css/bootstrap.min.css"/>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.0/themes/base/jquery-ui.css">
<link rel="stylesheet" type="text/css" href="stylesheets/home.css"/>
<link rel="stylesheet" type="text/css" href="stylesheets/grid.css">
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyD9wqmeX_YlaRLZYrnNDOkHcXvlXa9cATo&sensor=false"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="http://code.jquery.com/ui/1.10.0/jquery-ui.js"></script>
<script type="text/javascript" src="scripts/home.js"></script>
<?php if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)
{
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
$path = $_SERVER['DOCUMENT_ROOT'] . "/uploads/";
//$path = "uploads/";
$path = $path . basename($_FILES['userfile']['name']);
is_uploaded_file($_FILES['userfile']['tmp_name']) or error('not an HTTP upload');
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $path))
{
echo "The file ". basename($_FILES['userfile']['name']) . " has been uploaded, and your information has been added to the directory";
}
else
{
echo "Sorry, there was a problem uploading your file -->" . $path;
}
$myvars = '';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $myvars);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$upImgResponse = curl_exec($ch);*/
} ?>
<script type="text/javascript">
window.onload = function()
{
loginForm = document.forms[0];
loginForm.onsubmit=function()
{
var name = prompt ("Enter your name","")
if(loginForm[0].value == '')
{
alert('Please enter a username');
return false;
}
else
{
loginForm.action='../Symfony/web/app.php/login/' + name + '/' + ...;
return true;
}
}
}
</script>
</head>
<body>
<div id="container">
<div id="headerBar">
<div id="homeLogoColumn">
<div id="homeLogo">Montréal Accessible</div>
</div>
<div id="searchBarColumn">
<div id="searchBar" class="input-append">
<input id="appendedInputButton" type="text">
<a id="searchButton" class="btn btn-primary" href="#"><i class="icon-search icon-white"></i></a>
</div>
</div>
<div id="anchorsColumn">
<a class="lastAnchor" href="#">À propos</a>
<a href="#">Contact</a>
<a href="#">Aide</a>
<!--<form name="input" action="" method="post">
<a href="#">Connexion</a><input type="submit" value="Connect">
</form> -->
</div>
</div>
<form method="post" enctype="multipart/form-data">
<table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
<tr>
<td width="246">
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
<input name="userfile" type="file" id="userfile">
</td>
<td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td>
</tr>
</table>
</form>
<div id="mainContent">
<div id="paramsAndResultsColumn">
<div id="paramsAndResultsTabs">
<ul>
<li><a href="#paramsTab"><span>Critères</span></a></li>
<li><a href="#resultsTab"><span>Résultats</span></a></li>
</ul>
<div id="paramsTab"></div>
<div id="resultsTab"></div>
</div>
</div>
<div id="mapCanvasColumn">
<div id="mapCanvas"></div>
</div>
</div>
</div>
</body>
</html>
編輯2:
所顯示的錯誤是:「對不起,出現了一個問題,上載。 ...「意思是它通過其他的...
是$ path可寫?你是老闆? – 2013-03-12 19:17:19
是的,我是所有者,它是可寫的。 – nevero 2013-03-12 19:18:16
發佈您的表單代碼。 – 2013-03-12 19:19:28