Twentyoneth Posted January 10, 2007 Share Posted January 10, 2007 this is my script:[code]<?php $writedir = "files/"; $upl = $HTTP_POST_FILES['upl']; $rename = ($writedir . $_POST['rename']); $uploadfile = ($writedir . basename($HTTP_POST_FILES['upl']['name'])); echo ("writedir = " . $writedir . "<br>" . "upl = " . $upl . "<br>" . "rename = " . $rename . "<br>" . "uploadfile = " . $uploadfile); if($_POST['Upload']) { if (move_uploaded_file($upl, $uploadfile)) { rename($uploadfile, $rename); echo ("Your file was successfully uploaded.<br>"); } else { echo "Could not upload file.<br>"; } } else { echo "<form action='upload.php' enctype='multipart/form-data' method='POST'><input type='hidden' name='MAX_FILE_SIZE' value='9000000000000' /><table border='0'><tr><td> Browse for a file, give it a name. Then 'Upload' it.</td></tr><tr><td> <input type='file' name='upl' /></td></tr><tr><td> <input type='text' name='rename' /> <input type='submit' value='Upload' name='Upload' /></td></tr></table?</form>"; }?>[/code]For some reason, it will not read any of the post data. I tried to have it check what each little variable was holding but they are all empty. Can anyone help tell me what is wrong and get this script working? Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted January 10, 2007 Share Posted January 10, 2007 Use $_POST instead of $HTTP_POST_VARS$HTTP_*_VARS are depreciated. It is recommended you use the new superglobals $_POST, $_GET etc Quote Link to comment Share on other sites More sharing options...
Asheeown Posted January 10, 2007 Share Posted January 10, 2007 Uhm for one....wildteen hes not using $HTTP_POST_VARSSecond...Try checking your form page make sure your name is exactly "Upload" and if it is try making $_POST['Upload'] a variable such as[code]<?php$Upload = $_POST['Upload'];// To check if the variable is populatedecho $Upload;?>[/code] Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted January 10, 2007 Share Posted January 10, 2007 Use $_FILES instead of $HTTP_POST_FILES.At the start of the script put:[code]<?phpecho '$_POST:<pre>' . print_r($_POST,true) . '</pre>';echo '$_FILES:<pre>' . print_r($_FILES,true) . '</pre>';?>[/code]This will tell you what's being returned to your script from the form.Ken Quote Link to comment Share on other sites More sharing options...
Twentyoneth Posted January 11, 2007 Author Share Posted January 11, 2007 I tried what you said Ken, but it just shows this:[code]$_POST:Array()$_FILES:Array()[/code]Another thing, this is all in one file, the file is "upload.php".Thanks for the replies :)What do I try next? Quote Link to comment Share on other sites More sharing options...
lucasl Posted January 11, 2007 Share Posted January 11, 2007 This probably won't work, but it can't hurt to try. Try using $_SERVER['PHP_SELF'] instead of its own filename.Also, don't use tables if you can help it. :) Quote Link to comment Share on other sites More sharing options...
magic2goodil Posted January 11, 2007 Share Posted January 11, 2007 when posting a specific file as ken showed, i think he meant put something like $_FILES['upl']['name'] i put upl cuz i think u called it that..as wildteen said, and as i always use for files, try $_FILES instead of the HTTP_POST_FILES Quote Link to comment Share on other sites More sharing options...
Twentyoneth Posted January 11, 2007 Author Share Posted January 11, 2007 I've done that, and I tried the "$_SERVER['PHP_SELF']" thing, and nothing is happening.... Quote Link to comment Share on other sites More sharing options...
Guest rancid-tea Posted January 11, 2007 Share Posted January 11, 2007 Can you post your newest code? Quote Link to comment Share on other sites More sharing options...
Twentyoneth Posted January 11, 2007 Author Share Posted January 11, 2007 [code]<html><head></head><body><?php $writedir = "files/"; $upl = $_FILES['upl']; $uploadfile = ($writedir . $_POST['rename']); if($_POST['Upload']) { if (move_uploaded_file($upl, $uploadfile)) { echo ("writedir = " . $writedir . "<br>" . "upl = " . $upl . "<br>" . "rename = " . $rename . "<br>" . "uploadfile = " . $uploadfile . "<br>"); echo ("Your file was successfully uploaded.<br>"); } else { echo ("writedir = " . $writedir . "<br>" . "upl = " . $upl . "<br>" . "rename = " . $rename . "<br>" . "uploadfile = " . $uploadfile . "<br>"); echo "Could not upload file.<br>"; } } else {echo "<form action='" . $_SERVER['PHP_SELF'] . "' enctype='multipart/form-data' method='POST'><input type='hidden' name='MAX_FILE_SIZE' value='9000' /><table border='0'><tr><td> Browse for a file, give it a name (with extention). Then 'Upload' it.</td></tr><tr><td> <input type='file' name='upl' /></td></tr><tr><td> <input type='text' name='rename' /> <input type='submit' value='submit' name='Upload' /></td></tr></table></form>";}?></body></html>[/code] Quote Link to comment Share on other sites More sharing options...
Guest rancid-tea Posted January 11, 2007 Share Posted January 11, 2007 I was able to get it to function on my test server with the following modification:[code]...if (move_uploaded_file($_FILES['upl']['tmp_name'], $uploadfile)) { ...[/code]I also had to ensure that the files directory existed. To get your echo statements to print relevant information, I added :[code] $rename = $_POST['rename'];[/code]You don't need the above change if you have globals on, but you should use it to be safe.I also changed your long echo statement to this:[code]echo ("writedir = " . $writedir . "<br>\n upl = <pre>"); print_r($_FILES['upl']); echo ("</pre> " . "rename = " . $rename . "<br>\n" . "uploadfile = " . $uploadfile . "<br>");[/code]I hope that helps! Quote Link to comment Share on other sites More sharing options...
Twentyoneth Posted January 11, 2007 Author Share Posted January 11, 2007 When I hit submit, it just reloads the page...it doesnt even go to "if($_POST['Upload']) {"...so it doesn't start the code for uploading.... Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted January 11, 2007 Share Posted January 11, 2007 Are you clicking on the "submit" button or are you hitting the return or enter key? What browser are you using?Ken Quote Link to comment Share on other sites More sharing options...
Draicone Posted January 11, 2007 Share Posted January 11, 2007 Try adding a bit of HTML code to your form code:[code]<input type="hidden" name="upload" value="true" />[/code] Quote Link to comment Share on other sites More sharing options...
Twentyoneth Posted January 12, 2007 Author Share Posted January 12, 2007 I am using firefox, I have tried return/enter key, and using the mouse. I added the bit of code to my form and still nothing....I have also split the code up into two different files, one is the form in html, and the other (upload2.php) is only the php....and it still will not work, is it just my system? Quote Link to comment Share on other sites More sharing options...
Twentyoneth Posted January 14, 2007 Author Share Posted January 14, 2007 *bump* Quote Link to comment Share on other sites More sharing options...
Twentyoneth Posted January 16, 2007 Author Share Posted January 16, 2007 *BUMP* Quote Link to comment Share on other sites More sharing options...
Twentyoneth Posted January 21, 2007 Author Share Posted January 21, 2007 bump.....pwease Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 21, 2007 Share Posted January 21, 2007 Can you post the newest code? Quote Link to comment 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.