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 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测