Php Ajax图像上传与显示

Php Ajax图像上传与显示,php,ajax,file-upload,image-uploading,Php,Ajax,File Upload,Image Uploading,我正在使用php mysql,并使用ajax(jquery)上传图像。图像已成功上载,但在重新编辑正确显示的页面时,不会立即显示图像 当我使用此代码时,上载和显示正在工作 <?php // Set the upload folder path $target_path = "uploads/"; // Set the new path with the file name $target_path = $target_path . basename( $_FILES['myfile']['

我正在使用php mysql,并使用ajax(jquery)上传图像。图像已成功上载,但在重新编辑正确显示的页面时,不会立即显示图像

当我使用此代码时,上载和显示正在工作

<?php
// Set the upload folder path
$target_path = "uploads/";
// Set the new path with the file name
$target_path = $target_path . basename( $_FILES['myfile']['name']); 

// Move the file to the upload folder
if(move_uploaded_file($_FILES['myfile']['tmp_name'], $target_path)) {
// print the new image path in the page, and this will recevie the javascripts 'response' variable
echo $target_path;
} else{
// Set default the image path if any error in upload.
echo "default.jpg";
}

?>

上面的php代码是upload.php

您的问题似乎在JS部分。。。请发布你的JS代码…没有任何JS对他们两人都是一样的…。不管怎样,我发布的代码…$(“#profile_img”).attr('src',response);不会更新你的图像。看看@MarkusI。缓存的那个bcoz??但是我使用$('profile_img').attr('src'+newdate().getTime(),response)来解决这个问题;但是它也不起作用……顺便说一句,我在php中给出的第一个解决方案是有效的,并且对于相同的js代码没有缓存问题……您犯了一个重要错误:您不应该将日期添加到attributename。它必须是图像源的http get参数。。。Try:$('#profile_img').attr('src',response+'?'+new Date().getTime());
<?php
// Set the upload folder path
$place_file="";
$target_path = "1/";
$target_path1 = "1/image01.jpg";
// Set the new path with the file name
$target_path = $target_path ."image01.jpg"; 
// Move the file to the upload folder
$place_file=move_uploaded_file($_FILES['myfile']['tmp_name'], $target_path1);
echo $target_path;
?>
    new AjaxUpload(button,{
    action: 'upload.php', 
    name: 'myfile',
    onSubmit : function(file, ext){
        spinner.css('display', 'block');
        // you can disable upload button
        this.disable();
        },
    onComplete: function(file, response){
        button.stop(false,true).fadeOut(200);
        spinner.css('display', 'none');
        $('#profile_img').attr('src', response);
        // enable upload button
        this.enable();
    }
});