rockinruler Posted April 3, 2010 Share Posted April 3, 2010 Hi. I am 15 years old and trying to make a php upload page for my brothers assigment but my code doesnt work. the _FILE[file] variable itself doesn't get set. Please tell me where the problem is HTML : <HTML> <HEAD> <script type="text"> </script></HEAD> <BODY style="text-align:center"> <SCRIPT LANGUAGE="javascript"> function setOptions(chosen) { var val = chosen.options[chosen.selectedIndex].value; if (val== "Select1.1") { document.FORM1.SELECt3.style.display='none'; document.FORM1.SELECt2.style.display='none'; document.FORM1.SELECt4.style.display='none'; } if (val== "Syllabus") { document.FORM1.SELECt3.style.display='none'; document.FORM1.SELECt4.style.display='inline'; } if (val== "Computers"||val=="EXTC"||val=="Electronics" ||val=="IT" ||val=="Biomedical"||val=="Production" ||val=="Chemical") { document.FORM1.SELECt3.style.display='none'; document.FORM1.SELECt2.style.display='inline'; } if (val== "Fees") { document.FORM1.SELECt2.style.display='none'; document.FORM1.SELECt3.style.display='inline'; } if (val== "SEM1"||val== "SEM2"||val== "SEM3"||val== "SEM4") { document.FORM1.sub.style.display='inline'; document.FORM1.Ufile.style.display='inline'; } if (val== "Select2.1"||val=="Select1.1"||val=="Select3.1") { document.FORM1.sub.style.display='none'; document.FORM1.Ufile.style.display='none'; } if (val== "Select4.1"){ document.FORM1.SELECt2.style.display='none'; } } </SCRIPT> <form method="post" action="upload.php" enctype="multipart/form-data"> <br><br><select NAME="SELECT1" onchange="setOptions(this);" >  <Option value="Select1.1" selected="selected">Select any one option  <Option value="Syllabus">Syllabus  <Option value="Fees">Fees  <Option value="UP">University Papers  <Option value="SGM">Sports Game Shedules  <Option value="ETT">Exam Time Tables  <Option value="Disclosures">Disclosures </SELECT> <br><br><select NAME="SELECT4" id="SELECt4" style="display:none" onchange="setOptions(this);">  <Option value="Select4.1">Select any one option  <Option value="Computers">Computers  <Option value="EXTC">EXTC  <Option value="Electronics">Electronics  <Option value="IT">IT  <Option value="Biomedical">Biomedical  <Option value="Production">Production  <Option value="Chemical">Chemical </SELECT> <br><br><select NAME="SELECT2" id="SELECt2" style="display:none" onchange="setOptions(this);">  <Option value="Select2.1">Select any one option  <Option value="SEM1">SEM1  <Option value="SEM2">SEM2  <Option value="SEM3">SEM3  <Option value="SEM4">SEM4 </SELECT> <br><br><select NAME="SELECT3" id="SELECt3" style="display:none" onchange="setOptions(this);">  <Option value="Select3.1">Select any one option  <Option value="SEM1">SEM1  <Option value="SEM2">SEM2  <Option value="SEM3">SEM3  <Option value="SEM4">SEM4 </SELECT> <br><br> <Input type="file" name ="file" value="Browse" id="Ufile" style="display:none"> <br><br><Input type="submit" name="submit" value="Submit" id="sub" style="display:none"> </FORM> </BODY> </HTML> <html> <head> </head> <body> <?php if ($_FILES['file']['name'] != '') { echo "A file was uploaded."; } else { echo "No file was uploaded."; } $extension = pathinfo($_FILES['file']['name']); $exten = $extension['extension']; if($exten=="pdf") { if(is_uploaded_file($_FILES['file']['tmp_name'])) { move_uploaded_file($_FILES['file']['tmp_name'],"pqr/".$_FLIES['file']['tmp_name'].".".$exten); echo "Upload Sucessful<br />"; } echo 'Failed'; } else { echo '<li>File format not supported.\n'.$exten.'</li>'; } ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/197486-simple-file-upload-problem/ Share on other sites More sharing options...
ialsoagree Posted April 3, 2010 Share Posted April 3, 2010 Try changing: <Input type="file" name ="file" value="Browse" id="Ufile" style="display:none"> to: <Input type="file" name ="file" id="Ufile" style="display:none"> Link to comment https://forums.phpfreaks.com/topic/197486-simple-file-upload-problem/#findComment-1036548 Share on other sites More sharing options...
abhi_madhani Posted April 3, 2010 Share Posted April 3, 2010 Hi, Try making the changes that above user has mentioned. Otherwise try this below script that works for my project <input type='file' name='filename' size='25'> <input type='hidden' name='action' value='fileupload'><br> <input type=submit value='Upload File'>"; <?php //Catching the variable value for upload script and setting the maximum upload size of a file. $action = $_POST["action"]; $max_size = "1048576"; // Max size in BYTES (1MB) if ($action == 'fileupload') { if ($_FILES["filename"]["size"] > $max_size) die ("<b>File too big! Try again...</b>"); $location="./files/"; copy($_FILES["filename"]["tmp_name"],$location.$_FILES["filename"]["name"]) or die("<b>Unknown error!</b>"); $xlsfilelocation=$location.$_FILES["filename"]["name"]; echo "<b><br><br>File Uploaded.</b>"; // for debug --> $filename --> ".$destination."/".$filename_name."</h2>"; } ?> Regards, Abhishek Link to comment https://forums.phpfreaks.com/topic/197486-simple-file-upload-problem/#findComment-1036576 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.