First of all: i'm sorry for my english, i'll try to explain what i want but i'm sorry if i can't do it very well.
I'm trying to create a webpage to allow users to upload images to server, the page have url upload, and file upload, with radio button to select upload method.
My problem is that i don't know how to disable file upload when url radio is selected, for example:
url upload: the webpage read url and use that image. file upload: the webpage read file and use that image.
That's what i want, but the problem is when both is selected: the page upload the file and read url, but only if url radio is selected. If file radio is selected then url is ignored.
I know that the problem is that when you press submit button the file is uploaded, and then the php server check the selected radio button and what have to do.
Is there any mode to avoid file upload if url radio is selected?, here's the script of page:
<?php
if ($_POST) {
if ($_POST["filesource"] === "file"){
$fileread = $_FILES["file"]["tmp_name"];
}else{
$fileread = $_POST["url"];
}
if ($fileread){
include('includes/imgresize.php');
$image = new SimpleImage();
$image->load($fileread);
$image->resize(250,400);
$image->save('picture.jpg');
echo "La imagen subida es: <br>";
echo "<img src='picture.jpg'>";
echo die;
}else{
echo "No se ha seleccionado ningún archivo.";
echo die;
}
}
?>
<script>
function setrad(radbut){
document.getElementById(radbut).checked = true;
}
</script>
<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
<table>
<tr><td><input type="radio" name="filesource" value="url" id="urlrad" checked>URL:</td><td><input type="text" size="64" name="url" onClick="setrad('urlrad');"></td></tr>
<tr><td><input type="radio" name="filesource" value="file" id="filerad">File:</td><td><input type="file" size="50" name="file" id="file" onClick="setrad('filerad');"/></td></tr>
</table>
<input name="Submit" type="submit" id="submit" value="Submit" />
</form>
Thanks in advance :)