hi having hard time using move_uploaded_file function pass file new location. using ajax pass function process.php. hope can me.
here process.php
$target_dir = "../files-here/"; $filename = $_post['filename']; $path_url = $target_dir .$filename; if (file_exists($path_url)) { echo "sorry, file exists."; $uploadok = 0; } else { if(move_uploaded_file($filename, $path_url)) echo "the file".$filename."has been uploaded"; here form ajax.
echo "<form method='post' enctype='multipart/form-data' id='test_ajax'>"; echo "<input name='uploadedfile' type='file' id='custom-file-input' class='test-only' /><br/>"; echo "</form>"; echo '<button value="upload" id="custom-submit-input">upload</button>'; <script> jquery('#custom-submit-input').click(function(){ var filename = jquery('input[type=file]').val().replace(/.*(\/|\\)/, ''); jquery.post("file-here/process.php", { filename: filename }, function(data) { console.log(data); }); </script>
i'm not sure work expect. form never gets 'submitted', file doesn't uploaded , not processing uploaded file. might manage post filename of file, thats all.
you need to:
- submit form in usual way (using html)
- process uploaded file (using php)
- move uploaded file (using php)
your uploaded file exist in 'temporary' directory 'temporary' filename once uploaded, , need data $_files array. can use move_uploaded_file move temporary file final destination.
i'm not sure can 'ajax' of process.
Comments
Post a Comment