Jump to content


Photo

Link


  • Please log in to reply
8 replies to this topic

#1 wildross

wildross
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 28 March 2006 - 10:17 AM

ok im making an image uploader which on registration it creats a folder defined by the username picked in registration,

when the user logs in, it will upload to the user's folder, but on making an array for the users's dir i cant link the files that are there

eg,
$user = "test";
$file = " test.gif";

Then i would want the code like this yes?

echo "<tr>\n <td><img src=\"/images/jpg.gif\" /> <a href=\"$user/$file\"> $file </a></td>

i would expect the output of this to be "www.domain.com/test/test.gif" yes?

what im getting back is "www.domain.com//test.gif

Its completly droping the $user data

user is defined by

$user = "$logged[username]";

Please help

Thanks

#2 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 28 March 2006 - 10:22 AM

maby show us all the code as it's oviusly not selecting somthing further up the page to set as the $user variable
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#3 wildross

wildross
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 28 March 2006 - 10:24 AM

yeah sry, kinda new to php

<?php

   ob_start();
   include("config.php");
   if ($logged[username])
   {
      echo ("<center><b>$logged[username]</b></center>");
   }
   else
   {
      echo("You are not logged in");
   }



$totalsize=0;

$user = "$logged[username]";

function doFilesize($size, $base=2)
{
  $size = $size/(1024^$base);
  $out = round($size, 2);
  switch( $base )
  {
    case 1:
      $out .= "bytes";
      break;
    case 2:
      $out .= "KB";
      break;
    case 3:
      $out .= "MB";
      break;
    case 4:
      $out .= "GB";
      break;
  }
  return $out;
}

function show_dir($dir, $pos=2)
{
  global $totalsize;
  if($pos == 2)
    echo "<table border=\"1\">\n  <tr>\n    <th>File</th>\n    <th>Size</th><th>upload date</th>\n  </tr>\n";
  $handle = @opendir($dir);
  while ($file = @readdir ($handle))
  {
    if (eregi("^\.{1,2}$",$file))
      continue;
    if(is_dir($dir.$file))
    {
      echo " ";
      show_dir("$dir.$file/", $pos+3);
    }else{    
      $size=doFilesize(filesize($dir.$file));
    {

    }
      echo "<tr>\n <td><img src=\"/images/jpg.gif\" /> <a href=\"$file/$file\"> $file </a></td>\n    <td> $size </td><td> Date</td>\n  </tr>\n";
      $totalsize=$totalsize+$size;
    }
  }
  @closedir($handle);

  if($pos == 2) echo "</pre><hr>";
    return($totalsize);
}







$totalsize = show_dir("up/$user/");
echo "Total space used by images: ";
echo doFilesize($totalsize, 3);

?>
<br><br>
<?php
$directory = opendir("up/$user/"); 
while($item = readdir()){ 
    if(($item != ".") && ($item != "..")){ 
    $files[] = $item; 
    echo ""; 
    } 
}
$sizeofarray = count($files);
echo "The total amount of files is: <b>" . $sizeofarray . "</b>";
?>


#4 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 28 March 2006 - 10:34 AM

where is $logged set? can u post config.php too if it is set in there?
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#5 wildross

wildross
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 28 March 2006 - 10:40 AM

config contains

<?
   ob_start(); 
   $conn = mysql_connect("localhost","DATABASE USERNAME","DATABASE PASSWORD");
   mysql_select_db(DATABASE NAME) or die(mysql_error());
   $logged = MYSQL_QUERY("SELECT * from users WHERE id='$_COOKIE[id]' AND password =     '$_COOKIE[pass]'");
   $logged = mysql_fetch_array($logged);
?> 


thanks for all the help so far

#6 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 28 March 2006 - 10:52 AM

hmm it would seam that either username is not a field in your table else there is no calue for the username otherwise the username and password havn't been found in the table which means that either username or password is wrong..
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#7 wildross

wildross
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 28 March 2006 - 10:56 AM

The listing of the array is defined by $user though,

user x requests list, it displays the content of /up/userx/
user y requests list, it displays the content of /up/usery/

Which is where i got stuck on because if its defined the *user* once,,, it should be able to do it again with the linking of the files..?


#8 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 28 March 2006 - 11:12 AM

but if "SELECT * from users WHERE id='$_COOKIE[id]' AND password = '$_COOKIE[pass]'" isn't matching id and password in the table then no results are outputted.. maby do this just after including config.php

print_r($logged); and see what that outputs as that will echo all of the array inside $logged
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#9 wildross

wildross
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 28 March 2006 - 11:45 AM

all sorted, i would like to thank you for your help

the new code case you would like to know was this

echo "<tr>\n <td><img src=\"/images/jpg.gif\" /> <a href=\"$dir/$file\"> $file </a></td>

Changed to $dir as it was defined early in the page




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users