Skip to content Skip to sidebar Skip to footer

Upload A File Using Php And Javascript

I selected a image using: My javascript code: p_img =document.getElementById('pimg').value; param= 'pn='+p_im

Solution 1:

Use POST (form) to send data to the php file.

With $_FILES["pimg"]["tmp_name"] you can move the uploaded file (with the php function move_uploaded_file to you webserver.

Link to PHP Function http://php.net/manual/de/function.move-uploaded-file.php

Solution 2:

You can upload the file without page refresh using simple JavaScript and PHP. Using JavaScript, the file would be passed to the PHP file and using move_uploaded_file() function file would be uploaded to the server.

The live demo and source code would found from here - Upload file using JavaScript and PHP

Solution 3:

xmlhttp.open("GET","add_prod.php?"+param,false);  

i think open method's parameter must contain true.

Solution 4:

Create index.html file

<!DOCTYPE html><html><body><formaction="upload_file.php"method="post"enctype="multipart/form-data"><labelfor="file">Filename:</label><inputtype="file"name="file"id="file"><br><inputtype="submit"name="submit"value="Submit"></form></body></html>

Create Php file upload_file.php

<?phpif ($_FILES["file"]["error"] > 0) {
    echo"Error: " . $_FILES["file"]["error"] . "<br>";
} else {
    echo"Upload: " . $_FILES["file"]["name"] . "<br>";
    echo"Type: " . $_FILES["file"]["type"] . "<br>";
    echo"Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
    echo"Stored in: " . $_FILES["file"]["tmp_name"];
}

?>

Post a Comment for "Upload A File Using Php And Javascript"