Jump to content

[SOLVED] clearing $_FILES browse field before posting form


arsnova

Recommended Posts

I've written a form that loads multiple files into an array upon posting. Let's say the form has three inputs:

 

<form name="submission" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="500000" />
<input type="file" name="pr_img_file_array[]" />
<input type="file" name="pr_img_file_array[]" />
<input type="file" name="pr_img_file_array[]" />
<input type="submit" class="submit" name="Submit" value="SUBMIT" />
</form>

 

If a user clicks "browse" next to one of the form inputs, queues a file, then decides, "hey, I don't want to upload a file afterall," what is an appropriate way to prevent the field from validation (to clear the input box from containing a variable)? Does the file handler contain a function like 'unlink' for this purpose, or am I making this more complicated than needed?

 

Thanks, everyone.

Seems that form security prevents this from happening server-side, but javascript handles it nicely. I found the solution here (also read the comments):

 

http://gusiev.com/2009/04/clear-upload-file-input-field/

 

Thanks to the bloggers for this--in case the link becomes inactive, here's the stripped code I used:

<script> 
function clear_filebrowser(id) {
	var parent = document.getElementById(id).parentNode
	parent.innerHTML = parent.innerHTML;
}
</script> 

<html>
<div><input id="file_initial" type="file" name="pr_img_file_array[]" /></div>	
<a href="#" onclick="clear_filebrowser('file_initial'); return false;" />CLEAR</a>
</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.