首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在php中上载多个base64编码的图像

如何在php中上载多个base64编码的图像
EN

Stack Overflow用户
提问于 2018-07-26 10:45:10
回答 1查看 1K关注 0票数 1

代码语言:javascript
复制
$('.image-editor').each(function(){
  $(this).cropit();
});
$('.export').click(function(){
  var category = [];
  $("input[name='category']:checked").each(function(){
    category.push(this.value);
	});
  var imageData = [];
  $('.image-editor').each(function(){
      imageData.push( $(this).cropit() );
  });
  $.ajax({
      url: "upload.php",
      type: "POST",
      data: {
      imageData: imageData,
      category: category
    },
      success: function (result){
        alert(result);
    }
  });
});
代码语言:javascript
复制
.col100{
  width:100%;
}
.left{
  float:left;
}
.mbottom10{
  margin-bottom:20x;
}
.clearfix:after {
   content: " "; /* Older browser do not support empty content */
   visibility: hidden;
   display: block;
   height: 0;
   clear: both;
}

.image-editor{
	width: 100%;
	float:left;
}
.cropit-preview {
  float:left;
  background-color: #f8f8f8;
  background-size: cover;
  width: 200px;
  height: 150px;
}
.cropit-preview-image-container {
  cursor: move;
}
.image-size-label {
  margin-top: 10px;
}
代码语言:javascript
复制
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/cropit/0.5.1/jquery.cropit.min.js"></script>
<html>
<head>
</head>
<body>
  <section class="col100 left mbottom10">
    <input type="checkbox" name="category" value="1"> Slide
    <input type="checkbox" name="category" value="2" id="gallery"> Gallery
    <input type="submit" name="submit" class="export" />
	</section>
  <div class="clearfix"></div><br/>
  <article class="image-editor">
    <input type="file" class="cropit-image-input" /><br/>
    <input type="range" class="cropit-image-zoom-input" /><br/>
    <section class="cropit-preview"></section><br/>
   </article>
   <div class="clearfix"></div><br/>
  <article class="image-editor">
    <input type="file" class="cropit-image-input" /><br/>
    <input type="range" class="cropit-image-zoom-input" /><br/>
    <section class="cropit-preview"></section><br/>
   </article>
</body>
</html>

我试图上传多个base64 encoded image到服务器,但它只是上传第一个。在@ZakariaAcharki的帮助下,通过ajax传递多个图像形成数组之后,我在php中尝试了foreach loop。但是,只有一个和第一个图片是上传和提交!,下面的过程和代码是错误的根据ajax数据提供的小提琴?

代码语言:javascript
复制
foreach ($_POST["imageData"] AS $key => $category){
    $img = substr(explode(";",$category)[1], 7);
    $imgnm = time().'.jpg';
    $folder = '../images/slide/'.$imgnm;
    file_put_contents($folder, base64_decode($img));
}
EN

回答 1

Stack Overflow用户

发布于 2018-07-26 11:17:15

工作小提琴

是否可以将同一个CSS类的每个值存储在数组中?

是的,这可以尝试将其直接添加到数组中,例如:

代码语言:javascript
复制
var imageData = [];

$('.image-editor').each(function(){
    imageData.push( $(this).cropit('export') );
});
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51536963

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档