An7hony Posted May 26, 2010 Share Posted May 26, 2010 Here is some of my form: <form method="POST" enctype="multipart/form-data" action="" onsubmit="return false;" id="myid"> <label for="txtmessage" class="labsmall">Upload<span>*</span></label> <input type="hidden" name="MAX_FILE_SIZE" value="20000000000"><input name="userfile" type="file" class="browse" id="userfile"><br /> <input type="image" src="images/applybut.gif" class="applybutton" onclick="ajax_form('myid','validate.php','receiver');" /> Here is some of my validate.php: <? //file upload $uploadDir = '/blabla/'; $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; // get the file extension first $ext = substr(strrchr($fileName, "."), 1); // generate the random file name // and now we have the unique file name for the upload file $filePath = $uploadDir . $fileName; // move the files to the specified directory // if the upload directory is not writable or // something else went wrong $result will be false $result = move_uploaded_file($tmpName, $filePath); if (!$result) { echo 'Error uploading the <strong>file</strong>'; } $SQL = " INSERT INTO table "; $SQL = $SQL . " (name, size, type, path) VALUES "; $SQL = $SQL . " ('$fileName', '$fileSize', '$fileType', '$filePath') "; $result = mysql_db_query($db,"$SQL",$cid); if (!$result) { echo("ERROR: " . mysql_error() . "\n$SQL\n"); } mysql_close($cid); ?> Will this work using: onclick="ajax_form('myid','validate.php','receiver');" The rest of my data gets posted except the file upload Thanks for the help guys Quote Link to comment https://forums.phpfreaks.com/topic/202965-uploading-a-file/ Share on other sites More sharing options...
MadTechie Posted May 26, 2010 Share Posted May 26, 2010 You can't send file data via JS, So no it won't work Quote Link to comment https://forums.phpfreaks.com/topic/202965-uploading-a-file/#findComment-1063595 Share on other sites More sharing options...
An7hony Posted May 26, 2010 Author Share Posted May 26, 2010 ok thanks Quote Link to comment https://forums.phpfreaks.com/topic/202965-uploading-a-file/#findComment-1063602 Share on other sites More sharing options...
MadTechie Posted May 26, 2010 Share Posted May 26, 2010 To create a "ajax style" upload, your need to put the file input into an iframe or something then use JS to do a submit post, or something like that, its all down to security. Options options would be to use another client side language, ie java, flash etc or just have the upload on another page hope that helps Quote Link to comment https://forums.phpfreaks.com/topic/202965-uploading-a-file/#findComment-1063608 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.