dongshi1424 2018-10-17 15:16
浏览 28

为什么在Plesk Cpanel中我的连接正确时,图像上传会将错误视为“500内部服务器错误”

I have been Trying to upload an image in Plesk Cpanel from Godaddy. however, it gives me an error as " 500 Internal Server Error"

I checked my DB connections and they are perfect.

My code goes as:

<?php 
 include('../db.php'); 
  include('productadd.php'); 

$name = $_POST['name'];
$cat = $_POST['cat'];

$position = $_POST['position'];
$description = $_POST['description'];

$date = date_default_timezone_set('Asia/Kolkata');
$date = date('M-d,Y H:i:s');
$date2 = date('M-d,Y');

$file=($_FILES['file']['name']);

$conn = new mysqli ($servername, $dbusername, $dbpassword, $dbname);
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$sql = "INSERT INTO products (name, cat, position, description, pic, date)
VALUES ('$name', '$cat', '$position', '$description', '$file', '$date2')";

if ($conn->query($sql) === TRUE) {

$target_dir = "../images/products/";

$target_file2 = $target_dir . basename($_FILES["file"]["name"]);
$uploadOk2 = 1;
$imageFileType2 = strtolower(pathinfo($target_file2,PATHINFO_EXTENSION));

if ($uploadOk2 == 0) {
    echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
    if (move_uploaded_file($_FILES["file"]["tmp_name"], $target_file2)) {

echo '<script language="javascript">';
echo 'alert("Product has been Added successfully.")';
echo '</script>';
echo '<a href="productadd.php"></a>';

} else {
        echo "Sorry, there was an error uploading your file.";
    }
}

}
else {

}

?>

Here as you can see, I have a query for "insert" into a database which works fine and inserts a row in the DB along with the image name, but the file moving/uploading isn't working well.

If I try removing the file upload code and checked, it works fine by inserting the query in DB.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 csmar数据进行spss描述性统计分析
    • ¥15 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
    • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
    • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿
    • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
    • ¥15 运动想象脑电信号数据集.vhdr
    • ¥15 三因素重复测量数据R语句编写,不存在交互作用
    • ¥15 微信会员卡等级和折扣规则
    • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
    • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?