我正在尝试上传,重命名文件,然后发送到dB,这样我就可以显示裁剪的图像。为了使裁剪的图像与登录的用户对应,我需要在隐藏的输入字段中包含用户特定的数据。
这是我的HTML:
ls = [5,3,7,2,3,1]
minf [sd | ft <- [minf ls], sd <- ls,sd /= ft]
此处正在捕捉表格:
<div class="modal-body">
<form id="cropimage" method="post" enctype="multipart/form-data" action="change_pic.php">
<strong>Upload Image:</strong> <br><br>
<input type="file" name="profile-pic" id="profile-pic" />
<input type="hidden" name="hdn-profile-id" id="hdn-profile-id" value="<?php echo $user['id']; ?>" />
<input type="hidden" name="username-id" id="username-id" value="<?php echo $user['username']; ?>" />
<input type="hidden" name="hdn-x1-axis" id="hdn-x1-axis" value="" />
<input type="hidden" name="hdn-y1-axis" id="hdn-y1-axis" value="" />
<input type="hidden" name="hdn-x2-axis" value="" id="hdn-x2-axis" />
<input type="hidden" name="hdn-y2-axis" value="" id="hdn-y2-axis" />
<input type="hidden" name="hdn-thumb-width" id="hdn-thumb-width" value="" />
<input type="hidden" name="hdn-thumb-height" id="hdn-thumb-height" value="" />
<input type="hidden" name="action" value="" id="action" />
<input type="hidden" name="image_name" value="" id="image_name" />
<div id='preview-profile-pic'></div>
<div id="thumbs" style="padding:5px; width:600p"></div>
</form>
</div>
我要做的是进入构建function changeProfilePic() {
$post = isset($_POST) ? $_POST: array();
$max_width = "500";
$userId = isset($post['hdn-profile-id']) ? intval($post['hdn-profile-id']) : 0;
$username = isset($post['username-id']);
$path = 'assets/images/tmp';
$valid_formats = array("jpg", "png", "gif", "jpeg");
$name = $_FILES['profile-pic']['name'];
$size = $_FILES['profile-pic']['size'];
if(strlen($name)) {
list($txt, $ext) = explode(".", $name);
if(in_array($ext,$valid_formats)) {
if($size<(1024*1024)) {
$actual_image_name = 'avatar' . '_' . $username.'_'.$userId .'.'.$ext;
///etc,etc...
问题是,$actual_image_name = 'avatar' . '_' . $username.'_'.$userId .'.'.$ext;
始终以人员用户名$username
输出。所以我得到的文件名是1
avatar_1_11.jpg
我不明白。如果隐藏输入的值为avatar_john_smith_11.jpg
,并且我在<?php echo $user['username']; ?>
中根据id
检索该值,为什么要评估为1?我检错了吗?
答案 0 :(得分:1)
isset()
正在返回true
:
$username = isset($post['username-id']);
当您将其连接到1
时,会转换为字符串$actual_image_name
:
$actual_image_name = 'avatar' . '_' . $username.'_'.$userId .'.'.$ext;
你可以像对其他变量那样做:
$username = isset($post['username-id']) ? $post['username-id'] : '';
但是,为什么它没有设置,你应该如何处理呢?