Jump to content

I'm stumped...~~


ssjskipp

Recommended Posts

Okay, I'm trying to make an upload script, and here's how it's set up:
submit.php <-- contins the forms and HTML stuffs
upload.php <-- contains the upload scripts themselfs

on submit.php, this is the EXACT code:
[code]<?
include("check.php");
if ($_SESSION['on'] != 1 || $_SESSION['name'] != "ssjskipp"){
echo "Stop trying to add content, you NOT SSJSKIPP PERSON!<br/><br/><a href=\"javascript:void(0);\" onClick=\"history:back();\">Back</a>";
} else {
?>
<script language="JavaScript">
<!--
var ids = new Array('flash','music','art');

function switchid(id){
hideallids();
if (id != "ID"){
showdiv(id);
}
}

function hideallids(){
for (var i=0;i<ids.length;i++){
hidediv(ids[i]);
}  
}

function hidediv(id) {
if (document.getElementById) {
document.getElementById(id).style.display = 'none';
} else {
if (document.layers) {
document.id.display = 'none';
} else {
document.all.id.style.display = 'none';
}
}
}

function showdiv(id) {
if (document.getElementById) {
document.getElementById(id).style.display = 'block';
}
else {
if (document.layers) {
document.id.display = 'block';
} else {
document.all.id.style.display = 'block';
}
}
}
hideallids();
function validateForm(form){
var returnValue = true;
var error = 'The following field(s) are required and do not contain any information:\n';
//Flash
if (form.form.value == 'flash'){
if (!form.title.value){
form.title.className = 'reg_err';
error += '- Title\n';
returnValue = false;
}
if (!form.description.value){
form.description.className = 'reg_err';
error += "- Description\n";
returnValue = false;
}
if (!form.height.value){
form.height.className = 'reg_err';
error += "- height\n";
returnValue = false;
}
if (!form.width.value){
form.width.className = 'reg_err';
error += "- Width\n";
returnValue = false;
}
if (!form.userfile.value){
error += "- File\n";
returnValue = false;
}
}
if(returnValue == false){
alert(error);
}
return returnValue;
}
//-->
</script>
<form>
<table cellpadding="4" cellspacing="0" border="0" width="400" align="center">
<tr>
<td colspan="2" align="center"><span class="head">Upload Content</span></td>
</tr>
<tr>
<td colspan="2" align="center"><span class="small">Please fill in the following content with the correct information</span></td>
</tr>
<tr>
<td width="100" align="left">Type of upload:</td>
<td><select name="type" onChange="switchid(this.value);">
  <option value="ID">Upload Type</option>
  <option value="flash">Flash</option>
  <option value="music">Music</option>
  <option value="art">Art</option>
</select></td>
</tr>
</table>
</form>
<div id='flash' style="display:none;">
<form name="upload_f" method="post" action="index.php?page=upload" onSubmit="return validateForm(this);">
<input name="form_type" type="hidden" value="flash" />
<table cellpadding="4" cellspacing="0" border="0" width="400" align="center">
<tr>
<td colspan="2" align="center">Allowed File Types: .swf</td>
</tr>
<tr>
<td width="100">Title:</td>
<td><input type="text" name="title" maxlength="50" onblur="this.className='reg_def'" onfocus="this.className='reg'"></td>
</tr>
<tr>
<td width="100">Description:</td>
<td><textarea name="description" rows="5" cols="25" onblur="this.className='reg_def'" onfocus="this.className='reg'"></textarea></td>
</tr>
<tr>
<td width="100">Height:</td>
<td><input type="text" name="height" maxlength="5" onblur="this.className='reg_def'" onfocus="this.className='reg'"></td>
</tr>
<tr>
<td width="100">Width:</td>
<td><input type="text" name="width" maxlength="5" onblur="this.className='reg_def'" onfocus="this.className='reg'"></td>
</tr>
<tr>
<td width="100">File:</td>
<td><input type="file" name="userfile"></td>
</tr>
<tr>
<td colspan="2" align="center"><input name="Submit" type="submit" value="Submit"></td>
</tr>
</table>
</form>
</div>

<div id='music' style="display:none;">
<form name="upload_m" method="post" action="index.php?page=upload" onSubmit="return validateForm(this);">
<input name="form" type="hidden" value="music" />
<table cellpadding="4" cellspacing="0" border="0" width="400" align="center">
<tr>
<td colspan="2" align="center">Allowed File Types: .mp3</td>
</tr>
<tr>
<td width="100">Title:</td>
<td><input type="text" name="title" maxlength="50" onblur="this.className='reg_def'" onfocus="this.className='reg'"></td>
</tr>
<tr>
<td width="100">Description:</td>
<td><textarea name="description" rows="5" cols="25" onblur="this.className='reg_def'" onfocus="this.className='reg'"></textarea></td>
</tr>
<tr>
<td width="100">File:</td>
<td><input type="file" name="file"></td>
</tr>
<tr>
<td colspan="2" align="center"><input name="Submit" type="submit" value="Submit"></td>
</tr>
</table>
</form>
</div>

<div id='art' style="display:none;">
<form name="upload_a" method="post" action="index.php?page=upload" onSubmit="return validateForm(this);">
<input name="form" type="hidden" value="art" />
<table cellpadding="4" cellspacing="0" border="0" width="400" align="center">
<tr>
<td colspan="2" align="center">Allowed File Types: .png, .jpg, .gif, .bmp</td>
</tr>
<tr>
<td width="100">Title:</td>
<td><input type="text" name="title" maxlength="50" onblur="this.className='reg_def'" onfocus="this.className='reg'"></td>
</tr>
<tr>
<td width="100">Description:</td>
<td><textarea name="description" rows="5" cols="25" onblur="this.className='reg_def'" onfocus="this.className='reg'"></textarea></td>
</tr>
<tr>
<td width="100">File:</td>
<td><input name="userfile" type="file"></td>
</tr>
<tr>
<td colspan="2" align="center"><input name="Submit" type="submit" value="Submit"></td>
</tr>
</table>
</form>
</div>
<?
}
?>
<br/><br/>[/code]

Right now, just ignor Music and Art, unless that'll cause a problem.  What it does, is when you select something from the drop down, it'll update the page instantly and without loading again. When you submit, it'll tell you if something is missing before it submits, etc.

form_type is a hidden input field that contains which form is being used.

On upload.php, here's the script that I have [up to the error]:
[code]
if (!$_POST['form_type']){
echo "Error, have to pick something to submit, silly!<br /><a href=\"javascript:history.back();\">Back</a>";
$error = 2;
}
}
if ($error != 2){
if ($_POST['form_type'] == 'flash'){
$title = stripslashes($_POST['title']);
$desc = htmlentities($_POST['description'], ENT_QUOTES);
$height = stripslashes($_POST['height']);
$width = stripslashes($_POST['width']);
$userfile = $HTTP_POST_FILES['userfile']['tmp_name'];
$userfile_name = $HTTP_POST_FILES['userfile']['name'];
$userfile_size = $HTTP_POST_FILES['userfile']['size'];
$userfile_type = $HTTP_POST_FILES['userfile']['type'];
$userfile_error = $HTTP_POST_FILES['userfile']['error'];
}
if ($userfile_error > 0) {
echo 'Error: <br/>';
switch ($userfile_error) {
case 1: echo "File exceeded upload_max_filesize <a href=\"javascript:history.back();\">Back</a>"; break;
case 2: echo "File exceeded max_file_size <a href=\"javascript:history.back();\">Back</a>"; break;
case 3: echo "File only partially uploaded <a href=\"javascript:history.back();\">Back</a>"; break;
case 4: echo "No file uploaded <a href=\"javascript:history.back();\">Back</a>"; break;
}
$error = 2;
}
if ($error != 2){
if ($userfile_type != 'application/x-shockwave-flash') {
echo "File must be a flash file (.swf)<br /><a href=\"javascript:history.back();\">Back</a>";
$error = 2;
}
}
}[/code]

Where it messes up, is detecting the post varialbes for the files! I keep trying to echo the $userfile, $userfile_name, $userfile_size, $userfile_type, and $userfile_error variables, but they contain nothing..can anyone help!?
Link to comment
Share on other sites

As taken from the php manual (http://us3.php.net/manual/en/features.file-upload.php):

[quote]Example 38-1. File Upload Form

A file upload screen can be built by creating a special form which looks something like this:

<!-- 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>

The __URL__ in the above example should be replaced, and point to a PHP file. [/quote]

Put the entype="multipart/form-data" in your opening form tag.
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.