所以我在 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:
显示的错误是“抱歉,上传时出现问题...”,这意味着它会通过其他...