超薄表单不传递带有图像信息的数组

时间:2015-08-28 18:21:43

标签: php html forms file-upload slim

所以我有一个html表单,它正在传递我的图片(实际名称),但这就是我能得到的。当我尝试获取tmp_name或任何类似的东西时,它会显示错误。

另外,如果我的html表单没有声明def save(self, *args, **kwargs): data=self.cleaned_data regex = re.compile("\B#\w\w+") cleaned_tweets = data['tweets'] split_tweets = cleaned_tweets.split() obj = Tweet(tweets=data['tweets'], userprofile=self.userprofile, date=timezone.now(),) obj.save() hashtag_list = [] for x in (split_tweets): if re.search(regex, x): print x hashtag_list.append(x) new_list = list(set(hashtag_list)) print new_list obj_rel = Hashtags(users_tweet=obj, hashtag=x.replace("#", "")) obj_rel.save() else: return ValidationError('Something went wrong try again in a few seconds') ,我只能获取该文件的名称。

HTML

enctype

PHP

<form action="{{ urlFor('account.profile.post') }}" method="post" autocomplete="off">
  <!-- OTHER TEXT INPUTS THAT OUTPUT PERFECTLY FINE -->
  <div class="form-group">
    <label for="propic">Profile picture</label>
    <input type="file" id="propic" name="propic">
  </div>
</form>

1 个答案:

答案 0 :(得分:0)

您必须将表单的编码类型设置为multipart/form-data

<form action="{{ urlFor('account.profile.post') }}" method="post" autocomplete="off" enctype="multipart/form-data">

如果没有此编码类型,您将无法发送包含该表单的文件。

在你的php中,从文件中获取文件而不是post(不确定以下代码是否是在你正在使用的php框架中执行它的方式):

$propic = $app->request->files('propic');