Solarpitch Posted September 13, 2007 Share Posted September 13, 2007 I am having so much trouble trying to implement a simple file upload script on my site. The file doesnt seem to upload to the defined directory and just gives me the message "invalid file" as per last echo. I cant really see any problems to be honest The code... if ($_POST['process'] == 4) --> Just saying, if user clicked submit. { if (($_FILES["userfile"]["type"] == "image/gif") || ($_FILES["userfile"]["type"] == "image/jpeg") || ($_FILES["userfile"]["type"] == "image/pjpeg") && ($_FILES["userfile"]["size"] < 20000)) { if ($_FILES["userfile"]["error"] > 0) { echo "Return Code: " . $_FILES["userfile"]["error"] . "<br />"; $execute = "no"; } else { echo "Upload: " . $_FILES["userfile"]["name"] . "<br />"; echo "Type: " . $_FILES["userfile"]["type"] . "<br />"; echo "Size: " . ($_FILES["userfile"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["userfile"]["tmp_name"] . "<br />"; if (file_exists("user_images/" . $_FILES["userfile"]["name"])) { echo $_FILES["userfile"]["name"] . " already exists. "; $execute = "no"; } else { move_uploaded_file($_FILES["userfile"]["tmp_name"], "user_images/" . $_FILES["userfile"]["name"]); echo "Stored in: " . "user_images/" . $_FILES["userfile"]["name"]; $execute = "yes"; } } } else { echo "Invalid file"; } HTML ********* <form enctype="multipart/form-data" name="myform" method="post" action="upload_ad.php"> <input type="hidden" name="process" value="4"> <input type="submit" name="Submit" value="Submit Ad" onClick="return validate(this);"> Quote Link to comment https://forums.phpfreaks.com/topic/69217-problems-with-uploading-a-simple-file/ 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.