dqtm8504 2016-11-29 14:23
浏览 10

无法添加新的图像PHP / Mysql

I want to make it possible to update the hostage image with a new image but it's not working. It's using AJAX to send the data to the database. I get the following response from AJAX:

Temp/Thumb/6587_1480425818.pngimages
/acomodate/172/thumbnail/7483_1480052721.png
images/acomodate/172/thumbnail/2243_1480052767.png

And I am using the code below to add new images to the database. But when I run it nothing happens. It's not inserting the data into the table.

$r = $_REQUEST['id'];
$db21 = new Database();
$db21->connect();
$services = explode(',', $_REQUEST['allimg']);
$tot_ser = count($services);

for ($i = 0; $i < $tot_ser - 1; $i++)
{
echo $imgpath0 = $services[$i];
$ar0 = explode('/', $imgpath0);
$imgpath0 = $ar0[2];
if (!file_exists('../../images/acomodate/' . $r . '/'))
    {
    mkdir('../../images/acomodate/' . $r . '/', 0777, TRUE);
    }

if (!file_exists('../images/acomodate/' . $r . '/thumbnail/'))
    {
    mkdir('../images/acomodate/' . $r . '/thumbnail/', 0777, TRUE);
    }

rename('Temp/' . $imgpath0, '../images/acomodate/' . $r . '/');
rename('Temp/Thumb/' . $imgpath0, '../images/acomodate/' . $r . '/thumbnail/');
$db21->update('hostimages', array($r, $imgpath0) , 'hostid','image');
}

edit Database class for update

public function update($table,$rows,$where)
{                
    if($this->tableExists($table))
    {
        // Parse the where values
        // even values (including 0) contain the where rows
        // odd values contain the clauses for the row
        for($i = 0; $i < count($where); $i++)
        {
            if($i%2 != 0)
            {                    
                if(is_string($where[$i]))
                {
                    if(($i+1) != null)
                        $where[$i] = '"'.$where[$i].'"';
                    else
                        $where[$i] = '"'.$where[$i].'" AND';
                }
            }
        }

        $where = implode('',$where);


        $update = 'UPDATE '.$table.' SET ';
        $keys = array_keys($rows);
        for($i = 0; $i < count($rows); $i++)
        {
            if(is_string($rows[$keys[$i]]))
            {
                $update .= $keys[$i].'="'.$rows[$keys[$i]].'"';
            }
            else
            {
                $update .= $keys[$i].'='.$rows[$keys[$i]];
            }

            // Parse to add commas
            if($i != count($rows)-1)
            {
                $update .= ',';
            }
        }
        $update .= ' WHERE '.$where;
  //  echo $update;

         $query = @mysql_query($update);

        if($query)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    else
    {
        return false;
    }
}

Can you guys help me with it? Thank you.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 python的qt5界面
    • ¥15 无线电能传输系统MATLAB仿真问题
    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100