Jump to content

Uploading


MadDawgX

Recommended Posts

Hey there,

 

Im having some problems uploading a file using a form. Here's what I got:

 

if (isset($_POST['ffile'])) {
     $UploadPath = "uploads/";
     $UploadPath = $UploadPath . basename($_FILES['ffile']['name']);
     if(move_uploaded_file($_FILES['ffile']['tmp_name'],$UploadPath)) {
     $Upload = 1;
} else {
     $Upload = 3;
}			

 

And the file part of the form is:

 

<input type='file' name='ffile'/>

 

$Upload is returning 3 which the debug message for Upload Failed. Also, $UploadPath is only returning "uploads/"

 

Any help appreciated.

Link to comment
Share on other sites

<!-- The data encoding type, enctype, MUST be specified as below -->
<form enctype="multipart/form-data" action="__URL__" method="POST">
    <!-- MAX_FILE_SIZE must precede the file input field -->
    <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
    <!-- Name of input element determines name in $_FILES array -->
    Send this file: <input name="userfile" type="file" />
    <input type="submit" value="Send File" />
</form>

     

 

link please read

http://us2.php.net/features.file-upload

Link to comment
Share on other sites

Okay, the paging system I use works so that this file is included inside a table under the index.php file. Using the id and page to organize the files. So this would be id=3 and page=4 (4.php)

 

$Upload = 0;

// Upload File
if (isset($_POST['ffile'])) {
// File Values
$UploadFile = $_POST['ffile'];
$UploadPath = "uploads/";
$UploadPath = $UploadPath . basename($_FILES['ffile']['name']);
// New File
if (isset($_POST['fcat']) and isset($_POST['fname']) and isset($_POST['fdes'])) {
	if(move_uploaded_file($_FILES['ffile']['tmp_name'],$UploadPath)) {
		$Upload = 1;
	} else {
		$Upload = 3;
	}
}
}

// Header
echo "<table width='90%' height='2%' cellspacing='0' cellpadding='0' class='Head'>";
echo "<tr>";
echo "<td class='Head'>Upload File";
echo "<hr size='2' color='#CCCCC'>";
echo "</td>";
echo "</tr>";
echo "</table>";

f ($Upload == 0) {
// Draw Categories
echo "<table align='center' bordercolor='#000000' border='1' width='100%' cellpadding='3'";
	echo "style='margin: 0px; padding: 0px; border-collapse: collapse; border-color:#000000;'>";
// Title
echo "<tr bgcolor='#313131' class='textNormSmall'>";
	echo "<td colspan='3'>Upload File</td>";
echo "</tr>";
// Body
echo "<tr class='textNormSmallItalics'><td>";
	echo "<form action='index.php?id=3&page=4' method='post' enctype='multipart/form-data'>";
	echo "<table valign='top' class='textNormSmall' align='left'>";
		echo "<tr><td width='100'>Category:</td><td width='100'>";
			echo "<select class='textNormSmall' name='fcat'>";
			echo "<option>$LogUsername</option>";
			$qProject = "SELECT name FROM projects";
			$rProject = mysql_query($qProject) or die('Query failed. ' . mysql_error());	
			while ($rowProject = mysql_fetch_assoc($rProject)) {
				$ProjectName = $rowProject['name'];
				echo "<option>$ProjectName</option>";
			}
			echo "</select>";
			echo "</td></tr>";
		echo "<tr><td width='100'>Name:</td><td width='200'>";
			echo "<input class='textNormSmallItalics' name='fname' maxlength='40' type='text'>";
			echo "</td></tr>";
		echo "<tr><td width='100'>File:</td><td width='100'><input name='ffile' type='file' /></td></tr>";
		echo "<tr><td width='100'>Overwrite:</td><td width='100'><input name='fover' type='checkbox'/></td></tr>";
		echo "<tr><td width='100'>Description:</td><td width='100'>";
			echo "<textarea class='textNormSmallItalics' name='fdes' rows='12' cols='60'></textarea>";
			echo "</td></tr>";
	echo "</table>";
	echo "<br><center><input name='Submit' type='submit' value='Upload' /></center>";
	echo "</form>";
echo "</td></tr>";
echo "</table>";
} elseif ($Upload == 1) {
// Get File Id
$qFileId = "SELECT id FROM files WHERE loc='$UploadFile'";
$rFileId = mysql_query($qFileId) or die('Query failed. ' . mysql_error());	
$FileId = mysql_result($rFileId,0,'id');
echo "<div align='center' class='textNormSmall'>";
echo "<b><i><a href='index.php?id=3&page=2&file=$FileId'>File Uploaded. Click here to view the File.</a></i></b>";
echo "</div>";	
} elseif ($Upload == 2) {
$Error = "<div class='outError'>You do not have permission to edit overwrite this File!</div>";
echo "<center><table height='50' width='300'><tr><td>$Error</td></tr></table></center>";
} elseif ($Upload == 3) {
$Error = "<div class='outError'>Error! Could not upload File</div>";
echo "<center><table height='50' width='300'><tr><td>$Error</td></tr></table></center>";
}	


Link to comment
Share on other sites

indent ur code please cheers .

 

example


<?php

$Upload = 0;

// Upload File
if (isset($_POST['ffile'])) {

// File Values

$UploadFile = $_POST['ffile'];
$UploadPath = "uploads/";
$UploadPath = $UploadPath . basename($_FILES['ffile']['name']);

// New File

if (isset($_POST['fcat']) and isset($_POST['fname']) and isset($_POST['fdes'])) {
if(move_uploaded_file($_FILES['ffile']['tmp_name'],$UploadPath)) {

$Upload = 1;

} else {

$Upload = 3;
}
}
  }

// Header

echo "<table width='90%' height='2%' cellspacing='0' cellpadding='0' class='Head'>";

echo "<tr>";

echo "<td class='Head'>Upload File";

echo "<hr size='2' color='#CCCCC'>";

echo "</td>";
echo "</tr>";
echo "</table>";

if ($Upload == 0) {

// Draw Categories

echo "<table align='center' bordercolor='#000000' border='1' width='100%' cellpadding='3'";

echo "style='margin: 0px; padding: 0px; border-collapse: collapse; border-color:#000000;'>";

// Title

echo "<tr bgcolor='#313131' class='textNormSmall'>";

echo "<td colspan='3'>Upload File</td>";

echo "</tr>";

// Body

echo "<tr class='textNormSmallItalics'><td>";

echo "<form action='index.php?id=3&page=4' method='post' enctype='multipart/form-data'>";

echo "<table valign='top' class='textNormSmall' align='left'>";

echo "<tr><td width='100'>Category:</td><td width='100'>";

echo "<select class='textNormSmall' name='fcat'>";

echo "<option>$LogUsername</option>";

$qProject = "SELECT name FROM projects";

$rProject = mysql_query($qProject) or die('Query failed. ' . mysql_error());	

while ($rowProject = mysql_fetch_assoc($rProject)) {

$ProjectName = $rowProject['name'];

echo "<option>$ProjectName</option>";

}

echo "</select>";

echo "</td></tr>";

echo "<tr><td width='100'>Name:</td><td width='200'>";

echo "<input class='textNormSmallItalics' name='fname' maxlength='40' type='text'>";

echo "</td></tr>";

echo "<tr><td width='100'>File:</td><td width='100'><input name='ffile' type='file' /></td></tr>";

echo "<tr><td width='100'>Overwrite:</td><td width='100'><input name='fover' type='checkbox'/></td></tr>";

echo "<tr><td width='100'>Description:</td><td width='100'>";

echo "<textarea class='textNormSmallItalics' name='fdes' rows='12' cols='60'></textarea>";

echo "</td></tr>";

echo "</table>";

echo "<br><center><input name='Submit' type='submit' value='Upload' /></center>";

echo "</form>";

echo "</td></tr>";

echo "</table>";

} elseif ($Upload == 1) {

// Get File Id

$qFileId = "SELECT id FROM files WHERE loc='$UploadFile'";

$rFileId = mysql_query($qFileId) or die('Query failed. ' . mysql_error());	

$FileId = mysql_result($rFileId,0,'id');

echo "<div align='center' class='textNormSmall'>";

echo "<b><i><a href='index.php?id=3&page=2&file=$FileId'>File Uploaded. Click here to view the File.</a></i></b>";

echo "</div>";	

} elseif ($Upload == 2) {

$Error = "<div class='outError'>You do not have permission to edit overwrite this File!</div>";

echo "<center><table height='50' width='300'><tr><td>$Error</td></tr></table></center>";

} elseif ($Upload == 3) {

$Error = "<div class='outError'>Error! Could not upload File</div>";

echo "<center><table height='50' width='300'><tr><td>$Error</td></tr></table></center>";
}	
?>

Link to comment
Share on other sites

<?php

$Upload = 0;

if (isset($_POST['ffile'])) {


$UploadFile = $_POST['ffile'];
$UploadPath = "uploads/";
$UploadPath = $UploadPath . basename($_FILES['ffile']['name']);

if (isset($_POST['fcat']) && isset($_POST['fname']) && isset($_POST['fdes'])) {
if(move_uploaded_file($_FILES['ffile']['tmp_name'],$UploadPath)) {

$Upload = 1;

} else {

$Upload = 3;
}
}
  }
?>
<table width='90%' height='2%' cellspacing='0' cellpadding='0' class='Head'>

<tr>

<td class='Head'>Upload File

<hr size='2' color='#CCCCC'>

</td>

</tr>

</table>

<?php 

if ($Upload == 0) {

?>	

<table align='center' bordercolor='#000000' border='1' width='100%' cellpadding='3'";
style='margin: 0px; padding: 0px; border-collapse: collapse; border-color:#000000;'>

<tr bgcolor='#313131' class='textNormSmall'>

<td colspan='3'>Upload File</td>

</tr>

<tr class='textNormSmallItalics'><td>

<form action='index.php?id=3&page=4' method='post' enctype='multipart/form-data'>

<table valign='top' class='textNormSmall' align='left'>

<tr><td width='100'>Category:</td><td width='100'>

<select class='textNormSmall' name='fcat'>

<option><?php echo $LogUsername?></option>

<?php	

$qProject = "SELECT name FROM projects";

$rProject = mysql_query($qProject) or die('Query failed. ' . mysql_error());	

while ($rowProject = mysql_fetch_assoc($rProject)) {

$ProjectName = $rowProject['name'];
?>

<option><?php echo $ProjectName?></option>

<?php				
}
?>

</select>

</td></tr>

<tr><td width='100'>Name:</td><td width='200'>

<input class='textNormSmallItalics' name='fname' maxlength='40' type='text'>

</td></tr>

<tr><td width='100'>File:</td><td width='100'><input name='ffile' type='file' /></td></tr>

<tr><td width='100'>Overwrite:</td><td width='100'><input name='fover' type='checkbox'/></td></tr>

<tr><td width='100'>Description:</td><td width='100'>

<textarea class='textNormSmallItalics' name='fdes' rows='12' cols='60'></textarea>

</td></tr>

</table>

<br><center><input name='Submit' type='submit' value='Upload' ></center>

</form>

</td></tr>

</table>

<?php

} elseif ($Upload == 1) {

$qFileId = "SELECT id FROM files WHERE loc='$UploadFile'";

$rFileId = mysql_query($qFileId) or die('Query failed. ' . mysql_error());	

$FileId = mysql_result($rFileId,0,'id');
?>
<div align='center' class='textNormSmall'>

<b><i><a href='index.php?id=3&page=2&file=$FileId'>File Uploaded. Click here to view the File.</a></i></b>";

</div>	

<?php

} elseif ($Upload == 2) {

$Error = "<div class='outError'>You do not have permission to edit overwrite this File!</div>";

?>

<center><table height='50' width='300'><tr><td><?php echo $Error ?></td></tr></table></center>";

<?php

} elseif ($Upload == 3) {

$Error = "<div class='outError'>Error! Could not upload File</div>";

?>	
<center><table height='50' width='300'><tr><td><?php echo $Error?></td></tr></table></center>

<?php}?>	


 

 

where the database connection please cheers.

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.