D.Rattansingh Posted November 30, 2011 Share Posted November 30, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/252115-retrieving-an-image-with-php-sent-with-ajax/ Share on other sites More sharing options...
trq Posted November 30, 2011 Share Posted November 30, 2011 To send an image you would need to upload it. You cannot simply send a DOM node to php. Quote Link to comment https://forums.phpfreaks.com/topic/252115-retrieving-an-image-with-php-sent-with-ajax/#findComment-1292562 Share on other sites More sharing options...
D.Rattansingh Posted November 30, 2011 Author Share Posted November 30, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/252115-retrieving-an-image-with-php-sent-with-ajax/#findComment-1292563 Share on other sites More sharing options...
trq Posted November 30, 2011 Share Posted November 30, 2011 Iv'e not used Ajax to upload a file, but I'm sure there would be plenty of tutorials around on the subject. Quote Link to comment https://forums.phpfreaks.com/topic/252115-retrieving-an-image-with-php-sent-with-ajax/#findComment-1292564 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.