Jump to content

Retrieving an image with PHP sent with AJAX


D.Rattansingh

Recommended Posts

I'm trying to send a file over to a PHP script using GET with AJAX. Ajax is working fine however is there a way to send

an entire file over to PHP? This is since all I know thus far is we send strings via GET.

 

 

<script type="text/javascript">
var Load = function() {   
     var image = document.getElementById("img").value // here I could get the image value, i.e. the file name

     // sending with ajax
     XmlHttpRequest.open("GET", "server.php?id=17&image=" +image, true);
     ........ rest of ajax code
     // I know from the above all that would be sent would be the name, But is there a way to send the entire file so PHP could process?

    return false;
};
</script>
</head>
<body>

<form action=# method="post" onsubmit="return Load();">
    <input type="file" name="img" id="img">
    <input type="submit" value="Upload">
</form>

 

 

Could you clarify what you mean by upload it?

 

If I was using just PHP and HTML, I would post the HTML page onto the PHP page and upload the file directly.

 

I'm trying to use AJAX to do the same. The only problem is either directly or indirectly uploading it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.