Mudsaf Posted August 13, 2012 Share Posted August 13, 2012 (edited) Hello, im wondering how to create php page that can upload all the information with 1 page only. I tried to search at internet but could not find straight answer to my problem. Here is my code so far. echo "<center><form name='form9' enctype='multipart/form-data' method='GET' action='" . $_SERVER['PHP_SELF'] . "'> <label for='png'>Image:</label> <input type='file' name='png' id='png'> <input type='submit' name='upimage' id='upimage' value='Upload image'></form></center>"; if (isset($_GET['upimage'])) {$target_path = "../security/img/";$target_path = $target_path . basename( $_FILES['png']['name']);if(move_uploaded_file($_FILES['png']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['png']['name']). " has been uploaded";} else{echo "There was an error uploading the file, please try again!";}} Edited August 13, 2012 by Mudsaf Link to comment Share on other sites More sharing options...
justsomeguy Posted August 13, 2012 Share Posted August 13, 2012 File uploads don't work with "get" forms. Link to comment Share on other sites More sharing options...
Mudsaf Posted August 13, 2012 Author Share Posted August 13, 2012 Well how i would get this work with 1 page? Link to comment Share on other sites More sharing options...
justsomeguy Posted August 13, 2012 Share Posted August 13, 2012 Use a post form. 1 Link to comment Share on other sites More sharing options...
Mudsaf Posted August 13, 2012 Author Share Posted August 13, 2012 echo "<center><form name='form9' enctype='multipart/form-data' method='POST' action='" . $_SERVER['PHP_SELF'] . "'> <label for='png'>Image:</label> <input type='file' name='png' id='png'> <input type='submit' name='upimage' id='upimage' value='Upload image'></form></center>";if (isset($_POST['upimage'])) {$target_path = "../security/img/";$target_path = $target_path . basename( $_FILES['png']['name']);if(move_uploaded_file($_FILES['png']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['png']['name']). " has been uploaded";} else{echo "There was an error uploading the file, please try again!";}} Getting message "There was an error uploading the file, please try again!"; Link to comment Share on other sites More sharing options...
justsomeguy Posted August 13, 2012 Share Posted August 13, 2012 That means the move_uploaded_file call failed. If you're not seeing an error message from that then make sure your server is set to report errors. It may be storing error messages in an error log. You're also not checking for errors with the file upload, the $_FILES array includes an error code you should be checking. http://www.php.net/manual/en/features.file-upload.php Link to comment Share on other sites More sharing options...
Mudsaf Posted August 13, 2012 Author Share Posted August 13, 2012 Well i added this and echo $_FILES['png']["error"]; result was 0 Link to comment Share on other sites More sharing options...
Mudsaf Posted August 13, 2012 Author Share Posted August 13, 2012 Well solved, me idiot had wrong folder name "security" that was "%%_security" Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now