-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);
}
1
  • 1
    You need a hell a of a lot more code than that to upload a file. Or find a plugin Commented Dec 30, 2013 at 7:43

1 Answer 1

1

Try AJAX jQuery uploader.

Jquery File Upload 1

Jquery File Upload 2

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.