取消使用PHP提交webform [英] Cancel a webform submit with PHP

查看:61
本文介绍了取消使用PHP提交webform的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



当有人点击添加图片时,他们会被带到一个小图片上带有表单的页面。他们可以选择一个文件并点击提交按钮。



但是我现在想要做的是:在正常确认旁边放置第二个标有取消的提交按钮按钮。如果有人选择上传,选择并点击提交,如果在文件完全上传前按下取消按钮,PHP应该停止上传文件并将其删除。然后回到概述。



没有使用任何Javascript。



我只有localhost,所以测试这种不可能的,因为我只是复制一个文件毫秒我按下提交按钮。没有本地主机的上传时间,我不会为某个地方购买服务器。



基本上现在发生的事情是PHP检测到哪个按钮是发送。如果提交按钮已发送,则会上传该文件,如果发送取消按钮,则返回到概述。



但PHP在其中执行一项任务行。所以我认为这不会起作用。如何告诉PHP停止上传?

解决方案

你不能用php查看按钮 - 整个请求将在PHP获取该信息之前发送。



您可以将取消按钮置于不同的< form> ,如下所示:

 < form> < input type =file>< input type =submitvalue =upload>< / form> 
< form>< input type =submitvalue =cancel> ;< / form>

(这只是一个例子 - 缺少一些) / p>

当他们点击取消时,浏览器应放弃其请求并开始新的请求,取消上传。


I'm using a small site to experiment with the uploading of pictures and displaying them.

When someone clicks "add a picture", they get taken to a page with a form on it. They can select a file and click the submit button.

But what I want to do now is this: put a second submit button labeled "Cancel" next to the normal confirmation button. If someone then chooses to upload, selects and hits submit, if they press the cancel button before the file is fully uploaded, PHP should stop the uploading of the file and delete it. And then just go back to the overview.

No Javascript used whatsoever.

I only have localhost, so testing this in kindof impossible, since I just copy a file the millisecond I press the submit button. There's no upload-time with a localhost and I'm not going to buy a server somewhere just for this.

Basically what's happening now is that the PHP detects which button was sent. If the submit button was sent, the file is uploaded, if the cancel button is sent, it just goes back to the overview.

But PHP does its tasks one in a row. So I don't think this will work. How do I tell PHP to stop doing the upload?

解决方案

You can't look at the button with php - the whole request will have been sent before PHP gets that information.

What you could do is put the cancel button in a different <form>, like this:

<form> <input type="file> <input type="submit" value="upload"> </form>
<form> <input type="submit" value="cancel"> </form>

(This is just an example of course - there's bits missing).

When they click cancel, the browser should abandon its request and start a new one, cancelling the upload.

这篇关于取消使用PHP提交webform的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆