MadDawgX Posted February 12, 2007 Share Posted February 12, 2007 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 https://forums.phpfreaks.com/topic/38237-uploading/ Share on other sites More sharing options...
redarrow Posted February 12, 2007 Share Posted February 12, 2007 <!-- 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 https://forums.phpfreaks.com/topic/38237-uploading/#findComment-183150 Share on other sites More sharing options...
MadDawgX Posted February 12, 2007 Author Share Posted February 12, 2007 Okay, I've now got: <form action='index.php?id=3&page=4' method='post' enctype='multipart/form-data'> And the input field and upload code is the same. It now just sorta refreshes the page, and doesn't even display an error message. Link to comment https://forums.phpfreaks.com/topic/38237-uploading/#findComment-183158 Share on other sites More sharing options...
redarrow Posted February 12, 2007 Share Posted February 12, 2007 post your whole page ok. Link to comment https://forums.phpfreaks.com/topic/38237-uploading/#findComment-183160 Share on other sites More sharing options...
MadDawgX Posted February 12, 2007 Author Share Posted February 12, 2007 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 https://forums.phpfreaks.com/topic/38237-uploading/#findComment-183176 Share on other sites More sharing options...
redarrow Posted February 12, 2007 Share Posted February 12, 2007 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 https://forums.phpfreaks.com/topic/38237-uploading/#findComment-183178 Share on other sites More sharing options...
MadDawgX Posted February 13, 2007 Author Share Posted February 13, 2007 ahh my bad. Do you see an error? Link to comment https://forums.phpfreaks.com/topic/38237-uploading/#findComment-183181 Share on other sites More sharing options...
redarrow Posted February 13, 2007 Share Posted February 13, 2007 what is ffile do u mean ['file']? Link to comment https://forums.phpfreaks.com/topic/38237-uploading/#findComment-183182 Share on other sites More sharing options...
MadDawgX Posted February 13, 2007 Author Share Posted February 13, 2007 It's just ['ffile'] becuase all the other ones start with 'f' ( ['fdes'] ['fname'] etc.) I've got no problem with it being file, but does it really matter? Link to comment https://forums.phpfreaks.com/topic/38237-uploading/#findComment-183185 Share on other sites More sharing options...
redarrow Posted February 13, 2007 Share Posted February 13, 2007 <?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 https://forums.phpfreaks.com/topic/38237-uploading/#findComment-183194 Share on other sites More sharing options...
MadDawgX Posted February 13, 2007 Author Share Posted February 13, 2007 <?php // Connect Database $Db = mysql_connect ('***********','twistere_solace','*******); mysql_select_db ('twistere_team',$Db); ?> Link to comment https://forums.phpfreaks.com/topic/38237-uploading/#findComment-183201 Share on other sites More sharing options...
redarrow Posted February 13, 2007 Share Posted February 13, 2007 Does my example work? add the database ok and backup all old files to come back to. Link to comment https://forums.phpfreaks.com/topic/38237-uploading/#findComment-183204 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.