douiwn6941 2014-08-20 12:21
浏览 65
已采纳

尝试将图片目录插入MySQL数据库时出错

I have a form which is filed out by the user and a php script to insert the inputs into my table, however it keeps returning an error, I am able to insert all of the values other than the picture directory into the table.

These are my table values:

Field              Type             Null    
Name               Text             No
Picture            varchar(30)      No
Date               date             No
Price              int(11)          No

This is the form:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

        <meta http-equiv="content-type" content="text/html; charset=UTF-8">
        <link type="text/css" rel="stylesheet" href="stylesheet.css"/>

    </head>

<body>

<form method="post" action="addEvent.php" enctype="multipart/form-data">
    <p>
    Enter the Name of the Event:
      <input type="text" name ="Name"/>
    </p>
    <p>
    Picture:
      <input type="hidden" name="size" value="350000" />
      <input type="file" name="Photo" />
    </p>
    <p>
    Date:
      <input type="date" name="Date"/>
    </p>
    <p>
    Price
      <input type="number" name="Price"/>
    </p>
    <input type="submit" name="upload" title="Add data to the Database" value="Add   Event"/>
<br/>
<br/>
</form>

</body>
</html>

This is the script that I am using to insert the files into the database with the username and password of the database remove ofc.

<?php


$target = "public_html/events/Pictures";
$target = $target . basename( $_FILES['photo']['name']);


$name=$_POST['Name'];
$Picture=($_FILES['photo']['name']);
$Date=$_POST['Date'];
$Price=$_POST['Price'];



 mysql_connect("Host", "User", "pass") or      die(mysql_error()) ;
mysql_select_db("") or die(mysql_error()) ;


mysql_query("INSERT INTO Events (Name,Picture,Date,Price)
VALUES ('$name', '$Picture', '$Date', '$Price')") ;


if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
{


echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and     your information has been added to the directory";
}
else {


echo "Sorry, there was a problem uploading your file.";
}
?>

The script is currently returning the error "Sorry, there was a problem uploading your file."

Can anyone see what the problem is? The directory that I am trying to upload into is public_html/Events/Pictures

Any help would be appreciated, Thanks.

Edit: Changed the Script and now I am getting a new error.

<?php


$target = "public_html/events/Pictures/";
$target = $target . basename( $_FILES['Photo']['name']);


$name=$_POST['Name'];
$Picture=($_FILES['Photo']['name']);
$Date=$_POST['Date'];
$Price=$_POST['Price'];



 mysql_connect("mysql.hostinger.co.uk", "u219259269_admin", "password") or     die(mysql_error()) ;
mysql_select_db("u219259269_event") or die(mysql_error()) ;


mysql_query("INSERT INTO Events (Name,Picture,Date,Price)
VALUES ('$name', '$Picture', '$Date', '$Price')") ;


if(move_uploaded_file($_FILES['Photo']['tmp_name'], $target))
{


echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
  }
    else {

//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
?>

Warning: move_uploaded_file(public_html/events/Pictures/Test.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/u219259269/public_html/events/addEvent.php on line 31

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/php79Pc7Q' to 'public_html/events/Pictures/Test.jpg' in /home/u219259269/public_html/events/addEvent.php on line 31 Sorry, there was a problem uploading your file.

  • 写回答

2条回答 默认 最新

  • duanqian9593 2014-08-20 12:28
    关注

    Mostly, the question happens because :

    1) the path "public_html/Events/Pictures" not exist

    2) The PHP script has no permission to write the file into the directory.

    So you can check your public_html/Events/Pictures at first.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。