将上传图片与注册相结合


combining upload picture with registration

我想制作一个注册表格,用户应该能够在其中上传个人资料图片和注册表格。我正在使用类似于的ajax上传图片

 $(document).ready(function () {
     $('#UploadForm').on('submit', function (e) {
         e.preventDefault();
         $('#SubmitButton').attr('disabled', ''); // disable upload button
         //show uploading message
         $("#profile_picture").html('<div class ="update_load" style="padding:10px"><img class="load_pic" src="images/ajax-loader.gif" alt="Please Wait"/> </div>');
         $(this).ajaxSubmit({
             target: '#profile_picture',
             success: afterSuccess //call function after success
         });
     });
 });

ajax的反馈是这样的

echo '<img class="profile" src="uploads/'.$name.'.'.$ext.'" >';

现在,我想将另一个process.php文件上的$name变量转移到我当前的index.php文件中,这样我就可以使用MySQL查询插入它。我不知道该怎么做。我的第二个问题是,如果用户在注册表中多次更改图片,我如何删除他以前上传的所有图片?

好吧,这就是我所做的,我相信这可以帮助你:

1) 生成时间戳+随机数>幻数

2) 使用uploadify jquery插件将照片上传到临时文件夹(您可以从用户完成个人数据的同一表单上传照片

3) 以幻数作为名称保存该文件(您可以上传任意数量的文件来覆盖前一个

4) POST生成的数字以及带有用户数据的表单的其余部分

选择一个数字5):

5a)保存数据时,只需使用mysql 中的新id将临时文件重命名为最终文件夹

5b)保持临时文件的原样,只需将其移动到最终文件夹中,并使用幻数将其存储在数据库中

希望这能有所帮助!

您可以编写一个以响应为参数的afterSuccess函数。

$(this).ajaxSubmit({
             target: '#profile_picture',
             success: afterSuccess(data) //call function after success
         });
function afterSuccess(data)
{
    //parse your response to take the name
    //make another ajax request to save it to database
}

此功能也可以处理新图片上传。您将在php级别(称为ajax)中进行检查

解析img字符串以获取src,如下所示:

var img = $('<img class="profile" src="uploads/gaidouri.jpg" />');
var src = $(img).attr('src');