Jump to content

Upload page PHP (1 page only)


Mudsaf

Recommended Posts

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 by Mudsaf
Link to comment
Share on other sites

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...