我有文件输入的错误。诚然,图像已移至服务器的文件夹 - isset($_FILES['avatar']),没问题 - 但 user_avatar 的字段未填写您的姓名。它在数据库中以“default_130x130.png”命名。我应该如何将“$user_avatar”变量从 upload_image.php 发送到 new_user.php?
zh/users/new.html
<form id="avatar_file_upload_form" action="../../utils/upload_image.php" method="post" enctype='multipart/form-data'style="position:absolute;z-index:-10;height:1px;width:1px;overflow:hidden;visibility:hidden;">
<input type="file" name="avatar" id="avatar_file_upload_field" accept="image/jpeg,image/pjpeg,image/bmp,image/gif,image/jpeg,image/png"/>
<input type="submit" />
</form>
实用程序/upload_image.php
<?php
ob_start();
$mimeExt = array();
$mimeExt['image/jpeg'] ='.jpg';
$mimeExt['image/pjpeg'] ='.jpg';
$mimeExt['image/bmp'] ='.bmp';
$mimeExt['image/gif'] ='.gif';
$mimeExt['image/x-icon'] ='.ico';
$mimeExt['image/png'] ='.png';
if(isset($_FILES["avatar"])) {
//Begins image upload
$user_avatar = md5(uniqid(time())).$mimeExt[$_FILES["avatar"]["type"]]; //Get image extension
$user_avatar_dir = "../img/".$user_avatar; //Path file
move_uploaded_file($_FILES["avatar"]["tmp_name"], $user_avatar_dir);
} else {
$user_avatar = "default_130x130.png";
}
?>
新用户.php
<?php
ob_start();
include "config.php";
include "utils/upload_image.php";
$sql = mysql_query("insert into user(user_avatar) values('$user_avatar')", $db_connection) or die("Error: ".mysql_Error());
ob_end_clean();
mysql_close($db_connection);
?>
注意:“config.php”文件完美运行。