mrfruits Posted October 29, 2009 Share Posted October 29, 2009 Hi everyone I need some help with a bit of code ive been working with for a while. I am completely stumped to why it is now working correctly. <? if(!isset($upload)) { $upload = ""; } switch($upload) { default: include "config.php"; echo " <html> <head> <title>Upload</title> </head> <body topmargin=\"10\" leftmargin=\"0\" bgcolor=\"#1E1E2A\" link=\"#818EA0\" vlink=\"#5C697A\" alink=\"#818EA0\" text=\"#FFFFFF\" style=\"font-family: Verdana; font-size: 8pt; color: #FFFFFF\"> <div align=\"center\"> <center> <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#111111\" width=\"400\" id=\"AutoNumber1\"> <tr> <td bgcolor=\"#2A2B3A\" height=\"25\"> <p align=\"center\"><font size=\"2\"><b>Upload File</b></font></td> </tr> <tr> <td bgcolor=\"#2A2B3A\"><font size=\"2\">The following restrictions apply:</font><ul type=\"square\"> <li><font size=\"2\">Extension Allowed<b> (.jpeg, .gif, .jpg, .png)</b></font></li> <li><font size=\"2\">Maximum file size is two megs (2MB)</font></li> <li><font size=\"2\">No spaces in the filename</font></li> <li><font size=\"2\">No illegal characters(/,*,\,etc)</font><BR> </li> </ul> <form method=\"POST\" action=\"upload.php?upload=doupload\" enctype=\"multipart/form-data\"> <p align=\"center\"> <input type=file name=file size=30 style=\"font-family: v; font-size: 10pt; color: #5E6A7B; border: 1px solid #5E6A7B; padding-left: 4; padding-right: 4; padding-top: 1; padding-bottom: 1\"><br> <br> <button name=\"submit\" type=\"submit\" style=\"font-family: v; font-size: 10pt; color: #5E6A7B; border: 1px solid #5E6A7B; padding-left: 4; padding-right: 4; padding-top: 1; padding-bottom: 1\">Upload</button> </p> </form> <p> </td> </tr> </table> </center> </div> </body> </html>"; break; case "doupload": include "config.php"; $endresult = "<font size=\"2\">File Was Uploaded</font>"; if ($file_name == "") { $endresult = "<font size=\"2\">No file selected</font>"; }else{ if(file_exists("$absolute_path/$file_name")) { $endresult = "<font size=\"2\">File Already Existed</font>"; } else { if (($size_limit == "yes") && ($limit_size < $file_size)) { $endresult = "<font size=\"2\">File was to big</font>"; } else { $ext = strrchr($file_name,'.'); if (($limit_ext == "yes") && (!in_array($ext,$extensions))) { $endresult = "<font size=\"2\">File is wrong type</font>"; }else{ @copy($file, "$absolute_path/$file_name") or $endresult = "<font size=\"2\">Couldn't Copy File To Server</font>"; $myFile = "photolink.txt"; $fh = fopen($myFile, 'a') or die("can't open file"); $stringData = "\nhttp://www.penguinpowerhour.com/phphotos/"; fwrite($fh, $stringData); fwrite($fh, $file_name); fclose($fh); } } } } echo " <html> <head> <title>Upload</title> </head> <body topmargin=\"10\" leftmargin=\"0\" bgcolor=\"#1E1E2A\" link=\"#818EA0\" vlink=\"#5C697A\" alink=\"#818EA0\" text=\"#FFFFFF\" style=\"font-family: Verdana; font-size: 8pt; color: #FFFFFF\"> <div align=\"center\"> <center> <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#121316\" width=\"400\" id=\"AutoNumber1\"> <tr> <td bgcolor=\"#2A2B3A\" height=\"25\"> <p align=\"center\"><font size=\"2\"><b>Upload File</b></font></td> </tr> <tr> <td bgcolor=\"#1E1E2A\"> <center> $endresult </center> </td> </tr> </table> </center> </div> </body> </html>"; break; } ?> there is my code you can also test the code here to see what it does and wont do. http://www.penguinpowerhour.com/phphotos/upload.php it seems to only it the part were it tries to call the doupload function but it just wont. And I am at a loss to why it wont finish the script. Any help on this matter would be wonderful been messing with this a good part of the day. Thanks again! Link to comment https://forums.phpfreaks.com/topic/179438-upload-code-help/ Share on other sites More sharing options...
ngreenwood6 Posted October 29, 2009 Share Posted October 29, 2009 Well first of all I think you need to go back and look at how you are doing things. In your form tag you have the method as post, but when you post you are sending a get variable. you should pick one and stick with it. Also you are creating the html twice. You should only create the html once and switch the internal html with whether it was posted or not. Here is an example: <?php //if the form has been posted set the name if(isset($_POST['myName'])){ $name = $_POST['myName']; } else { $name = ''; } ?> <html> <body> <?php if(isset($_POST['myName'])){ echo "Thank you for submitting this form"; } ?> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> Enter your name : <input name="myName" type="text" value="<?php echo $name; ?>" /><br /> <input type="submit" value="submit" name="submit" /> </form> </body> </html> In that example I showed you two ways of doing this. The first one is by adding the text that they submitted the value. The other is actually putting the name in the textbox when it has been submitted. Usually you will want to check the submit buttons name versus the input's name. The reason for this is to check values. For instance if the user submits the form but doesnt submit a name it will not show as submitted. However, checking the submit buttons name will show as set because as you can see its value is "submit". Any questions just ask. Link to comment https://forums.phpfreaks.com/topic/179438-upload-code-help/#findComment-946839 Share on other sites More sharing options...
mrfruits Posted October 29, 2009 Author Share Posted October 29, 2009 I think you just confused me even more. But ill probably just have to start from scratch again. I am not that big on php so i dont know a lot of the syntax used. I just need this one script and then im done with php. But thank you for your reply. Link to comment https://forums.phpfreaks.com/topic/179438-upload-code-help/#findComment-946848 Share on other sites More sharing options...
priti Posted October 29, 2009 Share Posted October 29, 2009 As this is related to file upload ,we have just solved here :http://www.phpfreaks.com/forums/index.php/topic,274757.0.html Hope this help in understanding of file uploads. Link to comment https://forums.phpfreaks.com/topic/179438-upload-code-help/#findComment-946957 Share on other sites More sharing options...
ngreenwood6 Posted October 31, 2009 Share Posted October 31, 2009 You can copy my code and paste it into a php file to see what it does. Link to comment https://forums.phpfreaks.com/topic/179438-upload-code-help/#findComment-948186 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.