This Form successfully uploads, but then takes me to the next page. I'd like some assistance with how to stay on the same page, after upload, please. Any help will be appreciated. $allowedExts = array("gif", "jpeg", "jpg", "png"); $temp = explode(".", $_FILES["file"]["name"]); $extension = strtolower( end($temp) ); if ( $_FILES["file"]["size"] < 2000000 && in_array($extension, $allowedExts)){ if($_FILES["file"]["error"]!= 0){ echo "Return Code: " . $_FILES["file"]["error"] . "<br>"; }else{ $length = 20; $randomString = substr(str_shuffle(md5(time())),0,$length); $newfilename = $randomString . "." . $extension; move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $newfilename ); $file_location = '<a href="http://www.---.com/upload/' . $newfilename . '">http://www.---.com/upload/' . $newfilename . '</a>'; } }else{ echo "Invalid upload file"; } PHP: <form enctype="multipart/form-data" action="" method="POST"> <input type="file" name="file" id="file"> <input class="upload-video-form-input" type="hidden" name="form_submitted" value="yes" /> <input type="submit" value="submit" /> </form> HTML:
javascript/jquery handler for uploads! or start uploading in a new window target="_blank" or something
As long as both the PHP and HTML are in the same file (ie, your upload-handler is in the same file as the form), you shouldn't see any redirect - the code you posted above doesn't redirect anywhere, and the action-attribute is empty (which it shouldn't be, either omit it completely, if you're using HTML 5, or do action="#" if not) - hence there's nowhere for the script to go - unless you're not posting the actual code for us to see.
If you have a form you can easly, its just a fast copy past: if(isset($_POST['upload'])){ $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; $uploadDir = '../balbalba/'; $filePath = $uploadDir . $fileName; $result = move_uploaded_file($tmpName, $filePath); } <form action="<?php echo $PHP_SELF; ?>" method="post" enctype="multipart/form-data" >