0

好的,我在我的网站的函数文件中有这两个函数,它们也在那里将文件名移动到我的数据库以提取图像这是不工作的查询

function change_profile_image($user_id, $file_temp, $file_extn){
    $file_path = 'images/profile/' .substr(md5(time()), 0, 10). '.' . $file_extn;
    move_uploaded_file($file_temp, $file_path);
    mysql_query ("UPDATE `users` SET `profile` = '" . mysql_real_escape_string ($file_path) . "' WHERE `user_id` = " . (int)$user_id);
}



function portfolio_image($user_id, $file_temps, $file_extns ){
    $file_paths = 'images/portfolio/' .substr(md5(time()), 0, 9). '.' . $file_extns;
    move_uploaded_file($file_temps, $file_paths);
    mysql_query ("UPDATE `users` SET `image` = '" . mysql_real_escape_string ($file_paths) . "' WHERE `user_id` = " . (int)$user_id);

}

表格

<textarea name="last_name" placeholder="surname" class="name"><?php echo $user_data['last_name'] ?></textarea> <br>

<input class="proupload" type="file" name="profile"><input class="profilepicup" type="submit" value="Upload">

    <? if (isset($_FILES['profile']) === true){
     if (empty($_FILES['profile']['name'])=== true){
            echo "<p> please choose a file </p>";
     } else {
        $allowed = array('jpg','jpeg','gif','png');

        $file_name = $_FILES['profile']['name'];
        $file_extn = strtolower(end(explode('.', $file_name)));
        $file_temp = $_FILES['profile']['tmp_name'];

        if (in_array($file_extn, $allowed) === true) {
                change_profile_image($session_user_id, $file_temp, $file_extn );
        } else {
            echo '<p>Incorrect file type.</p>';

            }
            }
     }
 ?>



<form action= "portfolioupload.php" method ="post" enctype="multipart/form-data">

<input class="proupload" type="file" name="profile"><input class="profilepicup" type="submit" value="Upload">
    </form> 


        <?php if (isset($_FILES['profile']) === true){
     if (empty($_FILES['profile']['name'])=== true){
            echo "<p> please choose a file </p>";
     } else {
        $allowed = array('jpg','jpeg','gif','png');

        $file_name = $_FILES['profile']['name'];
        $file_extn = strtolower(end(explode('.', $file_name)));
        $file_temp = $_FILES['profile']['tmp_name'];

        if (in_array($file_extn, $allowed) === true) {
                portfolio_image($session_user_id, $file_temp, $file_extn );
        } else {
            echo '<p>Incorrect file type.</p>';

            }
            }
     }


?>

我已经将这些查询放在单独的页面上,它们可以工作 php 和 mysql 似乎不想在一个页面上处理两个图像上传,这很烦人,因为我还需要一个配置文件上传位和一个投资组合图像,这甚至可能吗?我是否必须将每张图片上传到单独的页面上:/

4

2 回答 2

1

我确定你有一个 var $file_path ..

mysql_query ("UPDATE `users` SET `portfolios` = '" . mysql_real_escape_string ($file_path) . "' WHERE `user_id` = " . (int)$user_id);

或者也许你有 $file_path 和 $file_paths ?

于 2013-05-24T00:12:31.817 回答
0

只需对它进行简单的错误处理即可or die(mysql_error())

mysql_query ("UPDATE `users` SET `profile` = '" . mysql_real_escape_string ($file_path) . "' WHERE `user_id` = " . (int)$user_id))or die(mysql_error());

编辑

好的,只需打开普通的 php 文件,连接到 db 并运行此查询

 mysql_query ("UPDATE `users` SET `profile` = 'test' WHERE `user_id` = '1')or die(mysql_error());

并检查您的数据库是否已更新,如果没有,您将收到一个可读错误。

于 2013-05-24T00:00:07.127 回答