Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
You can send a file to the server only through a [tt]form[/tt]. I see no actual need for AJAX here.arog123 said:So can I use AJAX and submit the file then on return display the image?
<html>
<head>
<script type="text/javascript">
function setsubmit()
{
document.forms[0].type.value='submit'
document.forms[0].target='_self'
}
function setpreview()
{
document.forms[0].type.value='preview'
document.forms[0].target='null'
}
</script>
</head>
<body>
<form action="up.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="type" value="submit">
Name : <input type="text" name="name"><br>
Image : <input type="file" name="image"> ( <input type="submit" value="Preview" onclick="setpreview()"> : <img src="" id="preview" height="100"> )<br>
Blah : <input type="text" name="blah"><br>
<input type="submit" onclick="setsubmit()"> <input type="reset">
</form>
<iframe src="about:blank" name="null">
</body>
</html>
<?php
if ($_POST[type]=='preview') {
if ($_FILES[image][error]==UPLOAD_ERR_OK) {
$name=basename($_FILES[image][name]);
move_uploaded_file($_FILES[image][tmp_name],$name);
}
?>
<html>
<head>
<script type="text/javascript">
parent.document.getElementById('preview').src='<?php echo $name; ?>'
</script>
</head>
<body>
</body>
</html>
<?php
return;
}
?>
<html>
<body>
Received :<br>
<pre>
<?php print_r($_POST); ?>
<?php print_r($_FILES); ?>
</pre>
</body>
</html>