當我使用接口訪問myserver索引並從那裏上傳和映像時,它工作正常。但只要我嘗試進入的路徑,像個:試圖上傳圖像時,爲什麼會出現此錯誤?
http://myserver/upload.php?image['name']=F:\Bilder\6.jpg
它給了我所需要的所有字段錯誤。但是我必須像這樣上傳圖像,因爲我打算在我製作的應用程序中實現它。事情是,我不熟悉PHP。
這裏是upload.php的
<?php
session_start();
require("includes/conn.php");
function is_valid_type($file)
{
$valid_types = array("image/jpg", "image/jpeg", "image/bmp", "image/gif", "image/png");
if (in_array($file['type'], $valid_types))
return 1;
return 0;
}
function showContents($array)
{
echo "<pre>";
print_r($array);
echo "</pre>";
}
$TARGET_PATH = "images/";
$image = $_FILES['image'];
$image['name'] = mysql_real_escape_string($image['name']);
$TARGET_PATH .= $image['name'];
if ($image['name'] == "")
{
$_SESSION['error'] = "All fields are required";
header("Location: index.php");
exit;
}
if (!is_valid_type($image))
{
$_SESSION['error'] = "You must upload a jpeg, gif, or bmp";
header("Location: index.php");
exit;
}
if (file_exists($TARGET_PATH))
{
$_SESSION['error'] = "A file with that name already exists";
header("Location: index.php");
exit;
}
if (move_uploaded_file($image['tmp_name'], $TARGET_PATH))
{
$sql = "insert into Avatar (filename) values ('" . $image['name'] . "')";
$result = mysql_query($sql) or die ("Could not insert data into DB: " . mysql_error());
exit;
}
else
{
header("Location: index.php");
exit;
}
?>
,並在index.php
<?php
if (isset($_SESSION['error']))
{
echo "<span id=\"error\"><p>" . $_SESSION['error'] . "</p></span>";
unset($_SESSION['error']);
}
?>
<form action="upload.php" method="post" enctype="multipart/form-data">
<p>
<label>Avatar</label>
<input type="file" name="image" /><br />
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
<input type="submit" id="submit" value="Upload" />
</p>
'http://myserver/upload.php?image ['name'] = F:\ Bilder \ 6.jpg'不是有效的PHP表達式。你究竟在什麼地方,哪個地方進入了這條路線? – bos 2012-02-18 15:54:47
那麼在我的瀏覽器中,爲了試圖給他一個圖像,而不使用索引接口 – Blade 2012-02-18 15:56:07