Jump to content


Photo

show username with file upload


  • Please log in to reply
7 replies to this topic

#1 drivethru

drivethru
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 19 September 2006 - 02:57 AM

Hey, I have an upload system on my website that allows people to upload files to the site. I have added a username/password system to the site since then. Users have to login to upload a video. Usernames are stored in a mySQL database. When users upload a file, how can I get their username shown to me so I know who sent me the file?

#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 19 September 2006 - 03:09 AM

<?php session_start();?>
<input type="hidden" name="<?php echo $name;?>">

add a colum called names to the upload colum.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 drivethru

drivethru
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 19 September 2006 - 03:50 AM

Thanks, but I'm still not real sure of what I'm supposed to do. Do I place that code in my "upload.php" or somewhere else and where will the name show up at?

#4 drivethru

drivethru
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 19 September 2006 - 03:51 PM

If this helps any, I'm using Simplicity oF Upload to upload my files. It sends me an email when a file is uploaded anyway. How can I get the username to show up in the email?

#5 Zane

Zane
  • Administrators
  • Advanced Member
  • 4,134 posts

Posted 19 September 2006 - 06:36 PM

I think the best idea for this would be to add the users ID number to the beggining of the filename

like if my ID is 9893
and the file I uploaded is called tree.jpg

set you code to rename it to 9893_tree.jpg
then you more systematically get the corresponding user

btn_donate_SM.gif Want to thank me? Contribute to my PayPal piggy-bank
 

172938.png

#6 drivethru

drivethru
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 20 September 2006 - 05:33 AM

That sounds like a really good idea. How do I get it to rename the file? Sorry, I'm still new to PHP.

#7 Zane

Zane
  • Administrators
  • Advanced Member
  • 4,134 posts

Posted 20 September 2006 - 06:26 PM

well, what does your code look like so far
show us some code and we can help you mold it to what you need.


btn_donate_SM.gif Want to thank me? Contribute to my PayPal piggy-bank
 

172938.png

#8 drivethru

drivethru
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 21 September 2006 - 03:39 AM

Here's what I have on my page to check to see if the user is logged in.
<?php
require 'db_connect.php';


if ($logged_in == 0) {
	die('Sorry you are not logged in, this area is restricted to registered members. <a href="login.php">Click here</a> to log in.');
}


// show content

$db_object->disconnect();
// when you are done.

?>

Here is my uploader
I also have a configuration file
<?php

require_once('SFUConfig.php');
require_once('functions.php');


if (SFU_CHANGE_LNG === true and isset($_GET['language'])) {
   $temp_language = strtolower($_GET['language']);

   if (!file_exists("$temp_language.lng")) {
      require_once("$language.lng");
      echo "($temp_language.lng) $txt[lng_doesnot_exist]<br />";
      echo $txt['lng_fall_default'];
   } else {
      $language = $temp_language;
   }
}

require_once("$language.lng");

$keys = array_keys($allowed);

foreach($keys as $one)
   if (!in_array(strtolower($one), array('text', 'exec', 'image', 'package'))) {
      html_header();
      echo '<p align="center"><span style="color:red; font-size: 12pt;"><b>'.$txt['unknown_attr'].': '.$one.'<br />'.$txt['unknown_notify'].'</b></span></p>';
      html_footer();
      exit;
   }

if (SFU_CHANGE_NUM === true && isset($_GET['num_files']) && is_numeric($_GET['num_files']))
   $num_files = (int)$_GET['num_files'];

foreach($allowed as $notyet)
   foreach($notyet as $final)
      $flat_allowed[] = strtolower($final);


html_header();

if (SFU_PROTECT == true) {
   session_start();

   if (isset($_POST['SFU_Protect'])) {
      if ($_POST['SFU_Protect'] == SFU_PASSWORD)
         $_SESSION['SFU_Protect'] = SFU_PASSWORD;
      else {
         echo $txt['pass_wrong'];
         html_footer();
         exit;
      }
   } elseif (!isset($_SESSION['SFU_Protect'])) {
      protectForm();
      html_footer();
      exit;
   } elseif ($_SESSION['SFU_Protect'] !== SFU_PASSWORD) {
      session_unset();
      session_destroy();
   }
}

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



   for ($i = 0; $i < $num_files; $i++) {

    
       if ($_FILES['SFUfile']['name'][$i] == '')
          continue;

       $File = strtr(stripslashes($_FILES['SFUfile']['name'][$i]), '\'" |\\/?!*#', '__________');

       $dotpos = strrpos($File, '.');
       $length = strlen($File);
       $ext    = strtolower(substr($File, -($length - $dotpos - 1)));
       $noext  = substr($File, 0, -($length - $dotpos - 1));

   
        if (!in_array($ext, $flat_allowed)) {
           LogErrors("{$txt['extension']} <b>$ext</b> {$txt['not_allowed']}");
           continue;
        }

        switch($_FILES['SFUfile']['error'][$i]) {
            case 0:
               break;
            case 1:
               LogErrors($txt['PHP_file_size']);
               continue 2;
               break;
            case 2:
               LogErrors("$txt[file_size] $txt[exceded_limit]");
               continue 2;
               break;
            case 3:
               LogErrors($txt['partial_upload']);
               continue 2;
               break;
            case 4:
               LogErrors($txt['no_file']);
               continue 2;
               break;
        }

    
        if ($_FILES['SFUfile']['size'][$i] > (SFU_MAXSIZE * 1024)) {
           LogErrors($txt['file_size'].' ('.round($_FILES['SFUfile']['size'][$i]/1024, 2)." $txt[KB]) {$txt['not_allowed']}");
           continue;
        }

        $fullname = SFU_REALPATH.$File;

        if (!isset($content))
           $content = '';


        if (SFU_OVERWRITE == false or !isset($_POST['SFUoverwrite'])) {
           if (file_exists($fullname)) {
              LogErrors($txt['file_exists']);
              continue;
           }

           if (isset($allowed['exec']) and in_array($ext, $allowed['exec'])) {
              if ($ext == 'php' and $highlight_php == true and file_exists(SFU_REALPATH.$noext.'html')) {
                 LogErrors($txt['exec_file_exists']);
                 continue;
              } elseif (file_exists(SFU_REALPATH.$noext.'txt')) {
                 LogErrors($txt['exec_file_exists']);
                 continue;
              }
           }
        }


        if(@move_uploaded_file($_FILES['SFUfile']['tmp_name'][$i], $fullname)) {

            if (isset($allowed['image']) and in_array($ext, $allowed['image']))
               is_image();

         
            elseif (isset($allowed['text']) and in_array($ext, $allowed['text']))
               is_text();

       
            elseif (isset($allowed['exec']) and in_array($ext, $allowed['exec']))
               is_exec();
            elseif (isset($allowed['package']) and in_array($ext, $allowed['package']))
               $uploaded[] = $File;


            if ($change_mode == true)
               @chmod($fullname, $mode)or
               LogErrors($txt['chmod_fail']);

   
        } else {
            LogErrors($txt['move_failiur'].'<br />'.$txt['try_again']);
            if (!file_exists(SFU_REALPATH))
               echo '<span style="color:red; font-size: 12pt;"><b>'.$txt['doesnot_exist'].'</b></span><br />';
            elseif (!is_writable(SFU_REALPATH))
               echo '<span style="color:red; font-size: 12pt;"><b>'.$txt['unwritable'].'</b></span><br />';
        }
   }


   if ($show_error_log == true and isset($errors) and count($errors) > 0)
      ShowErrorLog($errors);


   if ($show_uploaded_list == true and isset($uploaded) and count($uploaded) > 0)
      ShowUploaded($uploaded);


   if (isset($content))
      echo $content;

   if ($show_upload_form == true)
      PrintForm();

   if ($notify_admin == true)
      MailUploaded();

   if ($log_upload == true)
      FilesLogging();

} else
  PrintForm();

html_footer();


clearstatcache();
?>

EDITED by ZANUS - Try and use the code tags for such long code or any at that




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users