Uploading Failed

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
LiveFree
Forum Contributor
Posts: 258
Joined: Tue Dec 06, 2005 5:34 pm
Location: W-Town

Uploading Failed

Post by LiveFree »

Code: Select all

<?php
#### Generated by Module Creator - By Disipal site (http://www.disipal.net) ####
if (!eregi("modules.php", $PHP_SELF)) {
   die ("You can't access this file directly...");

}
require_once("mainfile.php");
$module_name = basename(dirname(__FILE__));
include("header.php");
$index = 0;
OpenTable();
/*
File: upload.php
Path: modules/Uploads/
*/
// Uploads a file
if (isset($_POST['submit'])){

if (empty($_POST['author'])){
  echo "Please enter in your in-game name!<br>";
}else{
  $added_by=$_POST['author'];
}

if (empty($_POST['desc'])){
  echo "Please enter in a short description!<br>";
}else{
  $desc=$_POST['desc'];
}

if ($_FILES['userfile']['size'] <= 524880){
  
	if (move_uploaded_file($_FILES['userfile']['tmp_name'], '/videos/')){
	  
	  echo "<b>File Uploaded!</b>";
	  $sql="INSERT INTO (id,filename,desc,added_by,datetime) VALUES ('','$_FILES[userfile][name]','$added_by',now())";
	  $result=mysql_query($sql) OR DIE (mysql_error());
	}else{
	  echo "Upload Failed!";
	}
  
}else{
  echo "The File you uploaded is too big! It must be below 5 Megabytes!";
}
  
}else{

echo '
<form enctype="multipart/form-data" action="modules.php?name=Upload&file=upload" method="POST">
    <input type="hidden" name="MAX_FILE_SIZE" value="5242880" />
    <!-- Name of input element determines name in $_FILES array -->
    <b>Upload:</b> <input name="userfile" type="file" /><br />
	    <b>Description:</b><input type="text" name="desc"><br />
    <b>Your Name:</b><input type="text" name="author"><br />
    <input type="submit" name="submit" value="Send File" />
    <input type="hidden" name="name" value="Upload">
    <input type="hidden" name="file" value="upload">
</form>';
}
CloseTable();
include('footer.php');
?>
http://www.clankoao.com/modules.php?nam ... ile=upload

It says Upload Failed

kthxcya

;)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

and? :?

you may want to verify that you have the right file size limitations..
yum-jelly
Forum Commoner
Posts: 98
Joined: Sat Oct 29, 2005 9:16 pm

Post by yum-jelly »

You cant move a file to just a directory name -> '/videos/'

Add the name of the file after that direcory name!

change this line....

Code: Select all

if (move_uploaded_file($_FILES['userfile']['tmp_name'], '/videos/')){

to this....

Code: Select all

if (move_uploaded_file($_FILES['userfile']['tmp_name'], '/videos/' . $_FILES['userfile']['name'])){

But you should also fix the script so you limit what can be uploaded!


yj!
LiveFree
Forum Contributor
Posts: 258
Joined: Tue Dec 06, 2005 5:34 pm
Location: W-Town

Post by LiveFree »

Updated Code:

Code: Select all

<?php
#### Generated by Module Creator - By Disipal site (http://www.disipal.net) ####
if (!eregi("modules.php", $PHP_SELF)) {
   die ("You can't access this file directly...");

}
require_once("mainfile.php");
$module_name = basename(dirname(__FILE__));
include("header.php");
$index = 0;
OpenTable();
/*
File: upload.php
Path: modules/Uploads/
*/
// Uploads a file

if (isset($_POST['submit'])){
  $uploaddir = '/videos/';
$uploadfile = $uploaddir.$_FILES['userfile']['name'];

if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
   echo "File is valid, and was successfully uploaded.\n";
} else {
   echo "Possible file upload attack!\n";
}

  
}else{
  echo '<!-- The data encoding type, enctype, MUST be specified as below -->
<form enctype="multipart/form-data" action="modules.php?name=Upload&file=upload" 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" />
    <input type="hidden" name="name" value="Upload" />
    <input type="hidden" name="file" value="upload" />
</form>';
}

CloseTable();
include('footer.php');
?>
http://www.clankoao.com/modules.php?name=Upload
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

missing name="submit" ;)
Post Reply