Php将图像上载到服务器
我在尝试将图像上载到服务器时遇到了一点问题。 以下是我遇到的错误: 注意:未定义的索引:$this->file in/opt/lampp/htdocs/xampp/php/theislan_testdatabase/addItem.php,位于第70行 注意:未定义的索引:$this->file in/opt/lampp/htdocs/xampp/php/theislan_testdatabase/addItem.php,位于第71行 注意:第72行的未定义索引:$this->file in/opt/lampp/htdocs/xampp/php/theislan_testdatabase/addItem.php 我想问题出在这个类的构造函数中Php将图像上载到服务器,php,image,forms,oop,get,Php,Image,Forms,Oop,Get,我在尝试将图像上载到服务器时遇到了一点问题。 以下是我遇到的错误: 注意:未定义的索引:$this->file in/opt/lampp/htdocs/xampp/php/theislan_testdatabase/addItem.php,位于第70行 注意:未定义的索引:$this->file in/opt/lampp/htdocs/xampp/php/theislan_testdatabase/addItem.php,位于第71行 注意:第72行的未定义索引:$this->file in/o
public function __construct() {
$this->submit = isset($_GET['submit'])? 1 : 0;
$this->errors = array();
//$this->product_id = $this->filter($_GET['product_id']);
$this->name = $this->filter($_GET['name']);
$this->description = $this->filter($_GET['description']);
$this->cost = $this->filter($_GET['cost']);
$this->numinstock = $this->filter($_GET['numinstock']);
//$this->picture = $this->filter($_GET['picture']);
$this->type = $this->filter($_GET['type']);
$this->file = $_GET['file'];
$this->token = $_GET['token'];
}
准确地说,这一行:$This->file=$\u GET['file']
这是那个类给我错误的部分
public function addNew() {
$databaseinst = database:: getinstance();
$conn = $databaseinst->connect();
$query = "INSERT INTO Product (name , description, cost, numinstock, type, image) VALUES ('$this->name', '$this->description',
'$this->cost','$this->numinstock', '$this->type', 'images/$this->name')";
//description = '$this->description' cost = '$this->cost' numinstock = '$this->numinstock' picture = '$this->picture' type = '$this->type'
$result = $databaseinst->querydb($query);
$id = mysql_insert_id();
//upload file
if ((($_FILES['$this->file']["type"] == "image/gif")
||($_FILES['$this->file']["type"] == "image/jpeg")
||($_FILES['$this->file']["type"] == "image/pjpeg"))
&&($_FILES['$this->file']["type"] < 40000000))
move_uploaded_file($_FILES["$this->file"]["tmp_name"],"images/" . $id.".jpq");
if ( false===$result ) {
$errorno =mysqli_errno($conn);
if ($errorno === 1062)
{
$this->errors[]= "this user already exists on the database. please try signing!";
}
else
{
$this->errors[]= "error creating new user
name = '$this->name' description = '$this->description' cost = '$this->cost' numinstock = '$this->numinstock'
type = '$this->type'
";
}
}
if($conn == null)
{
$this->errors[] = "difficulty is being experienced connecting to the server. Please try again in a moment!";
}
}
公共函数addNew(){
$databaseinst=数据库::getinstance();
$conn=$databaseinst->connect();
$query=“插入产品(名称、说明、成本、numinstock、类型、图像)值(‘$this->name’、‘$this->description’,
“$this->cost”、“$this->numinstock”、“$this->type”、“images/$this->name”);
//description='$this->description'cost='$this->cost'numinstock='$this->numinstock'picture='$this->picture'type='$this->type'
$result=$databaseinst->querydb($query);
$id=mysql_insert_id();
//上传文件
如果(($_FILES['$this->file'][“type”]==“image/gif”)
||($_文件['$this->file'][“type”]==“image/jpeg”)
||($_文件['$this->file'][“type”]==“image/pjpeg”))
&&($_文件['$this->file'][“type”]<40000000))
移动上传的文件($文件[“$this->file”][“tmp\u name”],“images/”$id.“.jpq”);
if(false==$result){
$errorno=mysqli\u errno($conn);
如果($errorno==1062)
{
$this->errors[]=“此用户已存在于数据库中。请尝试签名!”;
}
其他的
{
$this->errors[]=“创建新用户时出错
name='$this->name'description='$this->description'cost='$this->cost'numinstock='$this->numinstock'
类型=“$this->type”
";
}
}
如果($conn==null)
{
$this->errors[]=“连接到服务器时遇到困难。请稍后再试!”;
}
}
这是我获取用户输入的地方:
<li><b><cart><form method = "get" action="">
<?php
printf("<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"4000000\" />");
printf("<p>Name: <input type='text' name=\"name\" id=\"styled\";\"></p>");
printf("<p>Type: <input type='text' name=\"type\" id=\"styled\";\"></p>");
printf("<p>Picture: <input type=\"file\" name=\"file\" id=\"file\" \></p>");
printf("<p>Cost: <input type='text' onkeypress='validate(event)' name=\"cost\" id=\"styled\";\"></input></p>");
printf("<p>Number Instock: <input type='text' onkeypress='validate(event)' name=\"numinstock\" id=\"styled\";\"></p>");
printf("<p>Description: <textarea rows=\"6\" cols=\"200\" name=\"description\" id=\"styled\";\"></textarea></p>");
?>
<p><input type="submit" value="Add Item" name="submitAdd" />
<input type="hidden" name ="token" value="<?= $_SESSION['token']; ?>"
/></p></form></cart></b></li>
当文件用作索引时,不要在其周围加引号。哪些行是70、71和72?很抱歉,它们是:($U文件['$this->file'][“type”]=“image/gif”)|($U文件['$this->file'][“type”]=“image/jpeg”)|($U文件['$this->file'][“type”=“image/pjpeg”)))&($U文件['][“type”=“type”=“image/pjpeg”)&$<40000000))尝试用单引号更改双引号?=>$_文件['$this->file']['type']如果你删除它,如果检查是否有效?否,我得到:未定义的索引:bg_3_02.jpg in/opt/lampp/htdocs/xampp/php/theislan_testdatabase/addItem.php,在第69行,该行是:move_上传的_文件($this->file“[“tmp_name”],“images/“$id.”.jpq”);