好的,我在我的网站的函数文件中有这两个函数,它们也在那里将文件名移动到我的数据库以提取图像这是不工作的查询
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 似乎不想在一个页面上处理两个图像上传,这很烦人,因为我还需要一个配置文件上传位和一个投资组合图像,这甚至可能吗?我是否必须将每张图片上传到单独的页面上:/