-2

how to upload an image by javascript without submitting form in php? my requirement is to upload an image from my page without submitting the form.

index.html

<script>
function uploadme() {
    $('#redactor_content').redactor({
        imageUpload: 'process.php'
    });
}
</script>

<body>
<form action="process.php" method="post" enctype="multipart/form-data" name="frm">
    <input type="file" name="file" />
    <input type="button" onclick="uploadme()" value="upload" /> 
</form>
</body>

<br/>

process.php

$dir = 'upload/';
$_FILES['file']['type'] = strtolower($_FILES['file']['type']);
if ($_FILES['file']['type'] == 'image/png'
 || $_FILES['file']['type'] == 'image/jpg'
 || $_FILES['file']['type'] == 'image/gif'
 || $_FILES['file']['type'] == 'image/jpeg'
 || $_FILES['file']['type'] == 'image/pjpeg') {
    $file = $dir.$_FILES["file"]["name"];
    move_uploaded_file($_FILES['file']['tmp_name'], $file);
}
Sergey
  • 5,208
  • 25
  • 36
Neha
  • 1
  • 1
  • 4

1 Answers1

1

Try AJAX jQuery uploader.

Jquery File Upload 1

Jquery File Upload 2

Tony Jose
  • 1,654
  • 1
  • 13
  • 25