corillo181 Posted December 22, 2007 Share Posted December 22, 2007 hi! i'm new to the ajax world and i was trying to make a upload script, i made the js script that work fine, the php scrip that work fine, but my file wasn't been uploaded.. i did a var dumb to see the file that were been read by the $_post and the $_files what i could see from the result is that everything is working fine, but not the file. my question is how come everything in the form work but not the file? Quote Link to comment https://forums.phpfreaks.com/topic/82843-solved-php-ajax-trying/ Share on other sites More sharing options...
corillo181 Posted December 22, 2007 Author Share Posted December 22, 2007 mm no comments i guess the gurus are out to lunch, ill be bak later to check on any input.. Quote Link to comment https://forums.phpfreaks.com/topic/82843-solved-php-ajax-trying/#findComment-421340 Share on other sites More sharing options...
Barand Posted December 22, 2007 Share Posted December 22, 2007 The telepathy repairman calls Wednesdays. Check back then. Quote Link to comment https://forums.phpfreaks.com/topic/82843-solved-php-ajax-trying/#findComment-421345 Share on other sites More sharing options...
GingerRobot Posted December 22, 2007 Share Posted December 22, 2007 He calls on boxing day? Mine wont be out well into the new year. Quote Link to comment https://forums.phpfreaks.com/topic/82843-solved-php-ajax-trying/#findComment-421361 Share on other sites More sharing options...
corillo181 Posted December 23, 2007 Author Share Posted December 23, 2007 mm were those sarcastic comments because i don't get it :| Quote Link to comment https://forums.phpfreaks.com/topic/82843-solved-php-ajax-trying/#findComment-421478 Share on other sites More sharing options...
cooldude832 Posted December 23, 2007 Share Posted December 23, 2007 did you apply proper encryption for a file upload? Quote Link to comment https://forums.phpfreaks.com/topic/82843-solved-php-ajax-trying/#findComment-421489 Share on other sites More sharing options...
corillo181 Posted December 23, 2007 Author Share Posted December 23, 2007 ok let me post all the code ....... the form <form action="" method="post" enctype="multipart/form-data" title="add a party" onsubmit=" var s= doSubmit('test');return s;"> <fieldset> <h2>Add your party date.</h2> <p> <label title="date of your party">Date the date of your party :</label> <select name="month" id="month"> <option value="00">Month</option> <option value="January">01</option> <option value="February">02</option> <option value="March">03</option> <option value="April">04</option> <option value="May">05</option> <option value="June">06</option> <option value="July">07</option> <option value="Agust">08</option> <option value="September">09</option> <option value="Octuber">10</option> <option value="November">11</option> <option value="December">12</option> </select> <select name="day" id="day"> <option value="00">Day</option> <?php for($i=1;$i <=31; $i++){ echo "<option value=\"$i\">$i</option>"; } ?> </select> <select name="year" id="year"> <option value="00">Year</option> <?php for($i=date("Y");$i < date("Y")+5; $i++){ echo "<option value=\"$i\">$i</option>"; } ?> </select> </p> <p> <label for="imgfile">Flyer :</label> <input type="file" name="imgfile" id="imgfile" title="JPG image"/> <br /> </p> <p> <label for="desc">Description :</label> <input name="desc" type="text" id="desc" title="40 letter description" size="40" maxlength="40"/> </p> <p> <button type="submit" id="Upload" value="Upload">add this Party</button> </p> </fieldset> <fieldset> <h2>Keep in mind or you will get errors</h2> <ul> <li>Don't use a date that has already passed!</li> <li>Flyers has to be a JPG image</li> <li>The description has ot be less than 40 letters not 40 words</li> </ul> </fieldset> <fieldset> <h2>testing for results</h2> <div id="test"></div> </fieldset> </form> the JavaScript function doSubmit(div){ var year = "year=" + document.getElementById("year").value; var day = "day=" + document.getElementById("day").value; var month = "month=" + document.getElementById("month").value; var desc = "desc=" + document.getElementById("desc").value; var time = new Date(); var param = month+"&"+day+"&"+year+"&"+desc+"&"+"time="+time.getTime(); doAjax(div,'../../test2.php?',param); return false; } function doAjax(div,file,value){ var request = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"); if(request){ request.open("POST",file,true); request.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); request.setRequestHeader("Content-length", value.length); request.setRequestHeader("Connection", "close"); request.onreadystatechange = function(){ if(request.readyState == 4){ document.getElementById(div).innerHTML = request.responseText; } } request.send(value); } } Quote Link to comment https://forums.phpfreaks.com/topic/82843-solved-php-ajax-trying/#findComment-421497 Share on other sites More sharing options...
Stooney Posted December 23, 2007 Share Posted December 23, 2007 did u set the write permissions for the upload folder? Quote Link to comment https://forums.phpfreaks.com/topic/82843-solved-php-ajax-trying/#findComment-421521 Share on other sites More sharing options...
redarrow Posted December 23, 2007 Share Posted December 23, 2007 correct according to php.net uploading form format. <!-- The data encoding type, enctype, MUST be specified as below --> <form enctype="multipart/form-data" action="__URL__" method="POST"> <!-- MAX_FILE_SIZE must precede the file input field --> <input type="hidden" name="MAX_FILE_SIZE" value="30000" /> <!-- Name of input element determines name in $_FILES array --> Send this file: <input name="userfile" type="file" /> <input type="submit" value="Send File" /> </form> php.net upload link http://uk3.php.net/features.file-upload Quote Link to comment https://forums.phpfreaks.com/topic/82843-solved-php-ajax-trying/#findComment-421523 Share on other sites More sharing options...
Stooney Posted December 23, 2007 Share Posted December 23, 2007 I'm talking about the chmod of your upload directory. say you upload files to /uploads/files, you need to make sure to set the chmod to allow it. Try using 777 to test it out. (I'm assuming you haven't done this yet) Quote Link to comment https://forums.phpfreaks.com/topic/82843-solved-php-ajax-trying/#findComment-421547 Share on other sites More sharing options...
corillo181 Posted December 23, 2007 Author Share Posted December 23, 2007 does it matter the directory or the max file size of the values re not been read by the script? i have done many upload form so I'm sure of what i am doing. i never done it with Ajax so i am not sure why is the file properties are not been pass like the other properties? thats is my only question!! i been searching some other websites and found out the javascript or Ajax cannot handle file properties, but they are old documentations. is iframe the only why to upload files with out refreshing the current page? Quote Link to comment https://forums.phpfreaks.com/topic/82843-solved-php-ajax-trying/#findComment-421644 Share on other sites More sharing options...
Barand Posted December 23, 2007 Share Posted December 23, 2007 or create another window with the upload form. Unless the form is actually submitted I don't see how it can send the file. Quote Link to comment https://forums.phpfreaks.com/topic/82843-solved-php-ajax-trying/#findComment-421647 Share on other sites More sharing options...
corillo181 Posted December 23, 2007 Author Share Posted December 23, 2007 thank you, that was the sole answer to the question. Quote Link to comment https://forums.phpfreaks.com/topic/82843-solved-php-ajax-trying/#findComment-421648 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.