php上传图片到文件夹,php – jQuery / ajax上传图片并保存到文件夹

这篇博客讨论了如何使用jQuery和Ajax实现图片上传,并在用户选择的文件夹中保存原始图像。作者提供了代码示例,展示了一个基本的图像预览功能,并尝试通过Ajax将文件发送到PHP脚本进行保存。然而,作者遇到了问题,即不清楚如何正确传递文件数据。目前的代码可以成功触发回调,但需要进一步调整以正确发送和保存图像。
摘要由CSDN通过智能技术生成

更新下面的代码

我找到了一些能够上传图像并显示其缩略图的代码.但是,我想将图像保存到特定文件夹中.

我可以用什么jQuery代码或ajax代码将原始图像保存到我选择的文件夹中?

这是完整的代码:

.input-file-row-1:after {

content: ".";

display: block;

clear: both;

visibility: hidden;

line-height: 0;

height: 0;

}

.input-file-row-1{

display: inline-block;

margin-top: 25px;

position: relative;

}

#preview_image {

display: none;

width: 90px;

height: 90px;

margin: 2px 0px 0px 5px;

border-radius: 10px;

}

.upload-file-container {

position: relative;

width: 100px;

height: 137px;

overflow: hidden;

background: url(http://i.imgur.com/AeUEdJb.png) top center no-repeat;

float: left;

margin-left: 23px;

}

.upload-file-container-text{

font-family: Arial, sans-serif;

font-size: 12px;

color: #719d2b;

line-height: 17px;

text-align: center;

display: block;

position: absolute;

left: 0;

bottom: 0;

width: 100px;

height: 35px;

}

.upload-file-container-text > span{

border-bottom: 1px solid #719d2b;

cursor: pointer;

}

.one_opacity_0 {

opacity: 0;

height: 0;

width: 1px;

float: left;

}

$( document ).ready(function() {

function readURL(input, target) {

if (input.files && input.files[0]) {

var reader = new FileReader();

var image_target = $(target);

reader.onload = function (e) {

image_target.attr('src', e.target.result).show();

};

reader.readAsDataURL(input.files[0]);

}

}

$("#patient_pic").live("change",function(){

readURL(this, "#preview_image")

});

});

Add Photo

更新:我认为我走在正确的轨道上.我很接近,但我不知道从jQuery发送什么数据.我添加了一个php scrit,它的回调成功,但我没有发送正确的var.我想如果我发送正确的val我可以得到它.

码:

$( document ).ready(function() {

function readURL(input, target) {

if (input.files && input.files[0]) {

var reader = new FileReader();

var image_target = $(target);

reader.onload = function (e) {

image_target.attr('src', e.target.result).show();

$.ajax({

type:'POST',

url: 'theUpload.php',

data: input.files[0],

success:function(data){

console.log("success");

console.log(data);

alert(data);

},

error: function(data){

console.log("error");

console.log(data);

}

});

};

reader.readAsDataURL(input.files[0]);

}

}

$("#patient_pic").live("change",function(){

readURL(this, "#preview_image")

});

});

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值