Jump to content

Simple file upload problem


rockinruler

Recommended Posts

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);"  >
&nbsp<Option value="Select1.1" selected="selected">Select any one option
&nbsp<Option value="Syllabus">Syllabus
&nbsp<Option value="Fees">Fees
&nbsp<Option value="UP">University Papers
&nbsp<Option value="SGM">Sports Game Shedules
&nbsp<Option value="ETT">Exam Time Tables
&nbsp<Option value="Disclosures">Disclosures
</SELECT>

<br><br><select NAME="SELECT4" id="SELECt4" style="display:none" onchange="setOptions(this);">
&nbsp<Option value="Select4.1">Select any one option
&nbsp<Option value="Computers">Computers
&nbsp<Option value="EXTC">EXTC
&nbsp<Option value="Electronics">Electronics
&nbsp<Option value="IT">IT
&nbsp<Option value="Biomedical">Biomedical
&nbsp<Option value="Production">Production
&nbsp<Option value="Chemical">Chemical
</SELECT>



<br><br><select NAME="SELECT2" id="SELECt2" style="display:none" onchange="setOptions(this);">
&nbsp<Option value="Select2.1">Select any one option
&nbsp<Option value="SEM1">SEM1
&nbsp<Option value="SEM2">SEM2
&nbsp<Option value="SEM3">SEM3
&nbsp<Option value="SEM4">SEM4
</SELECT>


<br><br><select NAME="SELECT3" id="SELECt3" style="display:none" onchange="setOptions(this);">
&nbsp<Option value="Select3.1">Select any one option
&nbsp<Option value="SEM1">SEM1
&nbsp<Option value="SEM2">SEM2
&nbsp<Option value="SEM3">SEM3
&nbsp<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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.