Jump to content

file upload problems


chris_rulez001

Recommended Posts

hi whats wrong with this php file upload code:

 

<?php
  $action = $_GET['action'];
  
  switch($action)
  {
  default:
  if(!isset($_SESSION['username']) == false)
  {
  echo "<form enctype=\"multipart/form-data\" method=\"post\" action=\"?action=upload\">
<input type=\"file\" name=\"fileToUpload\" /><br />
<input type=\"submit\" value=\"Upload File\" />
</form><br/><br/>Maximum Video Size: 3 MB (3,000 KB)";
}
else
{
echo "<table width=\"400\" border=\"1\">
<tr>
<td align=\"center\">Access Denied</td>
</tr>
<tr>
<td align=\"center\">You are not allowed to view this page.</td>
</tr>
</table>";
}
  break;
  
  case upload:
  if (($_FILES["fileToUpload"]["type"] == "movie/mpeg4")
  || ($_FILES["fileToUpload"]["type"] == "movie/3gpp")
  && ($_FILES["fileToUpload"]["size"] < 3000))
  {
  move_uploaded_file($_FILES["fileToUpload"]["tmp_name"],
    "uservideos/" . $_FILES["fileToUpload"]["name"]);

echo "<table border=\"1\">";
echo "<tr><td>Client Filename: </td>
   <td>" . $_FILES["fileToUpload"]["name"] . "</td></tr>";
echo "<tr><td>File Type: </td>
   <td>" . $_FILES["fileToUpload"]["type"] . "</td></tr>";
echo "<tr><td>File Size: </td>
   <td>" . ($_FILES["fileToUpload"]["size"] / 1024) . " Kb</td></tr>";
echo "<tr><td>Name of Temporary File: </td>
   <td>" . $_FILES["fileToUpload"]["tmp_name"] . "</td></tr>";
echo "</table>";

echo "File Successfully Uploaded";
}
else
  {
  echo "Files must be either 3PG or MP4 and less than 3,000 KB (3 MB)<br/><br/><a href=\"javascript:history.go(-1)\">Go Back</a>";
  }
  break;
  }
?>

Link to comment
Share on other sites

check that your folder permissions are set to write. Though I'd highly suggest resetting them to 711 or lower after the upload.

 

If you don't know what I mean by that, use an ftp client to connect to your site, find the "uservideos" folder, right click and view properties. You should see some sort of 3 digit value somewhere(possibly starting with a 6 or 7). Tell us what it sas

Link to comment
Share on other sites

Ok well obviously you don't know what I'm talking about...

 

 

Download a program FileZilla...

 

 

then you have to connect to the site. You should have a username and password to login to your admin environment. Usually your domain will be ftp.yourdomain.com then username and password. Login. Find your 'uservideos' folder and right-click view properties. Then tell us the 3-digit value you see

Link to comment
Share on other sites

lol thats the error message you typed yourself. The way you have it setup is to display the error if the uploaded image isn't transferred successfully. It could be a ton of different things. I'm telling you, it's probably bc your folder's permissions aren't set to be written into

Link to comment
Share on other sites

Ok well obviously you don't know what I'm talking about...

 

 

Download a program FileZilla...

 

 

then you have to connect to the site. You should have a username and password to login to your admin environment. Usually your domain will be ftp.yourdomain.com then username and password. Login. Find your 'uservideos' folder and right-click view properties. Then tell us the 3-digit value you see

 

EDIT: nevermind, im just finding the 3 digit value

Link to comment
Share on other sites

Ok well obviously you don't know what I'm talking about...

 

 

Download a program FileZilla...

 

 

then you have to connect to the site. You should have a username and password to login to your admin environment. Usually your domain will be ftp.yourdomain.com then username and password. Login. Find your 'uservideos' folder and right-click view properties. Then tell us the 3-digit value you see

 

EDIT: nevermind, im just finding the 3 digit value

 

the 3 digit value is 755

Link to comment
Share on other sites

i have found something out.

 

this code works fine uploads all files but i would like to restrict all files exept 3gp and mp4 files:

 

<?php
  $action = $_GET['action'];
  
  switch($action)
  {
  default:
  if(!isset($_SESSION['username']) == false)
  {
  echo "<form enctype=\"multipart/form-data\" method=\"post\" action=\"?action=upload\">
<input type=\"file\" name=\"fileToUpload\" /><br />
<input type=\"submit\" value=\"Upload File\" />
</form><br/><br/>Maximum Video Size: 3 MB (3,000 KB)";
}
else
{
echo "<table width=\"400\" border=\"1\">
<tr>
<td align=\"center\">Access Denied</td>
</tr>
<tr>
<td align=\"center\">You are not allowed to view this page.</td>
</tr>
</table>";
}
  break;
  
  case upload:
  if (($_FILES["fileToUpload"]["type"] == "video/mpeg4")
  || ($_FILES["fileToUpload"]["type"] == "video/3gpp")
  && ($_FILES["fileToUpload"]["size"] < 3000))
  {
  echo "Files must be either 3PG or MP4 and less than 3,000 KB (3 MB)<br/><br/><a href=\"javascript:history.go(-1)\">Go Back</a>";
  	}
else
  {
  move_uploaded_file($_FILES["fileToUpload"]["tmp_name"],
    "uservideos/" . $_FILES["fileToUpload"]["name"]);

echo "<table border=\"1\">";
echo "<tr><td>Client Filename: </td>
   <td>" . $_FILES["fileToUpload"]["name"] . "</td></tr>";
echo "<tr><td>File Type: </td>
   <td>" . $_FILES["fileToUpload"]["type"] . "</td></tr>";
echo "<tr><td>File Size: </td>
   <td>" . ($_FILES["fileToUpload"]["size"] / 1024) . " Kb</td></tr>";
echo "<tr><td>Name of Temporary File: </td>
   <td>" . $_FILES["fileToUpload"]["tmp_name"] . "</td></tr>";
echo "</table>";

echo "<br/>File Successfully Uploaded.<br/><br/><a href=\"upload.php\">Upload More Videos</a> Or <a href=\"index.php\">Return To Homepage</a>";
  }
  break;
  }
?>

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.