Please help me file name and folder name when upload by by browser Folder and file name it does not array .. A B C-Z or 1-9 ..please help me to fix this problem... Really thanks
the cause is when i moved to new hosting it happen like this problem
Pleaseeeee... fix this problem to help.. i don;t know how to fix it ( coz this is a open source and i don't know about php that much )

<?

require_once ("../include/errorhandling.php");
require_once ("../include/config.php");

$GLOBALS["rootdp"] = '../';
include ("../include/access.php");



include ("../include/functions.php");
include ("../include/settings.php");
include ("../".$GLOBALS["language_home"].$GLOBALS["gsLanguage"]."/lang_admin.php");
include ("../".$GLOBALS["language_home"].$GLOBALS["gsLanguage"]."/lang_images.php");

if (!isset($HTTP_GET_VARS["subdir"]))
{
   $subdir = '';
}
else
{
   $subdir = $HTTP_GET_VARS["subdir"];
}

$ImageFileTypes[] = "gif";
$ImageFileTypes[] = "jpg";
$ImageFileTypes[] = "png";

force_page_refresh();
frmImages();


function frmImages()
{
   global $ImageFileTypes, $subdir;
   global $HTTP_GET_VARS;
?>
   <html>
   <head>
   <LINK HREF="<? echo $GLOBALS["rootdp"].$GLOBALS["style_home"]; ?>vs.css" REL=STYLESHEET TYPE="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=windows-874">
   </head>
   <body leftmargin=0 topmargin=0 marginwidth="0" marginheight="0" bgcolor="#000000">
   <table border="0" width="100%" cellspacing="3" cellpadding="3">
   <tr bgcolor="#505050">
      <td colspan="4" align="center">
         <b><? echo $GLOBALS["tFormTitle"]; ?></b>
      </td>
   </tr><?

   // Generate image tags for the different images that appear on the page
$GLOBALS["iFirst"]  = lsimagehtmltag($GLOBALS["icon_home"],'first1.gif',$GLOBALS["gsLanguage"],$GLOBALS["tFirstPage"],0);
   $GLOBALS["iPrev"]   = lsimagehtmltag($GLOBALS["icon_home"],'last1.gif',$GLOBALS["gsLanguage"],$GLOBALS["tPrevPage"],0);
   $GLOBALS["iNext"]   = lsimagehtmltag($GLOBALS["icon_home"],'next1.gif',$GLOBALS["gsLanguage"],$GLOBALS["tNextPage"],0);
   $GLOBALS["iLast"]   = lsimagehtmltag($GLOBALS["icon_home"],'end1.gif',$GLOBALS["gsLanguage"],$GLOBALS["tLastPage"],0);
   $GLOBALS["iAddNew"] = lsimagehtmltag($GLOBALS["icon_home"],'addnew.gif',$GLOBALS["gsLanguage"],$GLOBALS["tAddNewMenu"],0);
    $iDelete = lsimagehtmltag($GLOBALS["icon_home"],'del_e-wrs.gif',$GLOBALS["gsLanguage"],$GLOBALS["tDeleteMenu"],0);
   $iOpenFolder = lsimagehtmltag($GLOBALS["icon_home"],'floderphotos2.gif','',0,'');
   $iBlank = lsimagehtmltag($GLOBALS["icon_home"],'blank.gif','',0,'');

   if($HTTP_GET_VARS["page"] != "")
   {
      $nCurrentPage = $HTTP_GET_VARS["page"];
   }
   else
   {
      $nCurrentPage = 0;
   }

   $lRecCount = lCountImages();
   $nPages = intval(($lRecCount - 0.5) / $GLOBALS["RECORDS_PER_PAGE"]) + 1;
   $lStartRec = $nCurrentPage * $GLOBALS["RECORDS_PER_PAGE"];

   frmImagesHdFt(4,$nCurrentPage,$nPages);
   ?>
   $array = $GLOBALS[$tImageName];
   <tr bgcolor="#99CC00">
      <td colspan="4" align="left"><? echo $GLOBALS["image_home"].$subdir ?></td>
   </tr>
   <tr bgcolor="#FFCC00">
      <td width="30%"><b><? echo $GLOBALS["tDel"]; ?></b></td>
      <td width="40%"><b><? echo $GLOBALS["tImageName"]; ?></b></td>
      <td width="15%">&nbsp;</td>
      <td width="15%">&nbsp;</td>
   </tr><?

   $nImageNr = 0;
   $nImageShowed = 0;

   $savedir = getcwd();
   chdir($GLOBALS["rootdp"].$GLOBALS["image_home"].$subdir);

   if ($handle = @opendir('.'))
   {
      while ($file = readdir($handle))
      {
         $filename = $file;
         if (is_file($filename))
         {
            $fileparts = pathinfo($filename);
            $file_ext = $fileparts["extension"];
            if (in_array($file_ext,$ImageFileTypes))
            {
               if ($nImageNr >= $lStartRec && $nImageShowed < $GLOBALS["RECORDS_PER_PAGE"])
               {
                  ?><tr bgcolor="#99CCFF">
                  <td align="center" valign="middle">
                  <? echo $iBlank; ?>
                  <a href="javascript:DelImage('subdir=<? echo $subdir; ?>&Image=<? echo $file; ?>&page=<? echo $HTTP_GET_VARS["page"]; ?>')"><? echo $iDelete; ?></a>
                  </td>
                  <td valign="top"><a href="javascript:ShowImage('<? echo $GLOBALS["rootdp"].$GLOBALS["image_home"].$subdir.$file; ?>')"><? echo $file; ?></a></td>
                  <td align="right" valign="top"><? echo display_size(filesize($file)); ?></td><?
                  $size = GetImageSize($filename);
                  $imagesize1 = $size["0"];
                  $imagesize2 = $size["1"]; ?>
                  <td align="center" valign="top"><? echo $imagesize1.' x '.$imagesize2; ?></td>
                  </tr><?
                  $nImageShowed++;
               }
               $nImageNr++;
            }
         }
         elseif (is_dir($filename))
         {
            if ((($subdir != '') && ($filename != '.')) || (($subdir == '') && ($filename != '.') && ($filename != '..')))
            {
               if ($nImageNr >= $lStartRec && $nImageShowed < $GLOBALS["RECORDS_PER_PAGE"])
               {
                  if ($filename != '..')
                  {
                     $newsubdir = $subdir.$filename.'/';
                  }
                  else
                  {
                     $dirbreakdown = explode('/',$subdir);
                     array_pop($dirbreakdown); array_pop($dirbreakdown);
                     $newsubdir = implode('/',$dirbreakdown).'/';
                     if ($newsubdir == '/')
                     {
                        $newsubdir = '';
                     }
                  }

                  ?><tr bgcolor="#6699FF">
                  <td align="center" valign="middle"><?

                  if ($filename != '..')
                  {
                     ?><a href="m_images.php?subdir=<? echo $newsubdir; ?>"><? echo $iOpenFolder; ?></a>
                     <a href="javascript:DelDir('subdir=<? echo $subdir; ?>&folder=<? echo $file; ?>&page=<? echo $HTTP_GET_VARS["page"]; ?>')"><? echo $iDelete; ?></a><?
                  }

                  ?></td>
                  <td valign="top"><a href="m_images.php?subdir=<? echo $newsubdir; ?>"><? echo $filename; ?></a></td>
                  <td align="center" valign="middle">&nbsp;</td>
                  <td align="center" valign="middle">&nbsp;</td>
                  </tr><?
                  $nImageShowed++;
               }
               $nImageNr++;
            }
         }
      }
      closedir($handle);
   }
   chdir($savedir);

   frmImagesHdFt(4,$nCurrentPage,$nPages);
   ?>
   </table>
   </body>
   </html><?
} // function frmImages()


function lCountImages()
{
   global $ImageFileTypes, $subdir;

   $nImageCount = 0;
   $savedir = getcwd();
   chdir($GLOBALS["rootdp"].$GLOBALS["image_home"].$subdir);

   if ($handle = @opendir('.'))
   {
      while ($file = readdir($handle))
      {
         $filename = $file;
         if (is_file($filename))
         {
            $fileparts = pathinfo($filename);
            $file_ext = $fileparts["extension"];
             if (in_array($file_ext,$ImageFileTypes))
             {
               $nImageCount++;
            }
         }
         elseif
         (is_dir($filename))
         {
            if (($subdir != '') || ($filename != '..'))
            {
               $nImageCount++;
            }
         }
      }

      closedir($handle);
   }
   chdir($savedir);

   return $nImageCount;
} // function lCountImages()

?>

<script language="Javascript">

function DelImage(sParams)
{
   if(window.confirm('<? echo $GLOBALS["tConfirmDeletion"]; ?>'))
   {
      location.href='m_imagedel.php?' + sParams;
   }
}

function DelDir(sParams)
{
   if(window.confirm('<? echo $GLOBALS["tConfirmDeletion"]; ?>'))
   {
      location.href='removedir.php?' + sParams;
   }
}

function ShowImage(sImageName)
{
   window.open(sImageName, "Image", "width=500,height=400,status=no,resizable=yes,scrollbars=yes");
}

function UploadImage()
{
   window.open("uploadimage.php?subdir=<? echo $subdir; ?>", "UploadImage", "width=600,height=310,status=no,resizable=no,scrollbars=no");
}

</script>
<?


function frmImagesHdFt($colspan,$nCurrentPage,$nPages)
{
   global $subdir;
?>
   <tr bgcolor="#FFFFFF">
      <td colspan="<? echo $colspan; ?>" align="left">
         <table height="100%" width="100%" cellspacing="0" cellpadding="0">
            <tr>
               <td align="left" valign="bottom">
                  <a href="javascript:UploadImage();"><? echo $GLOBALS["iAddNew"]; ?></a>
               </td>

        <td align="right" valign="bottom"><font face="Arial Black" size="1" color="#CC0000"> 
          <a href="m_images.php?subdir=<? echo $subdir; ?>&page=0"> 
          <? echo $GLOBALS["iFirst"]; ?>
          </a> 
          <?
                  if ($nCurrentPage != 0)
                  {
                     ?>
          <a href="m_images.php?subdir=<? echo $subdir; ?>&page=<? echo $nCurrentPage - 1; ?>"> 
          <? echo $GLOBALS["iPrev"]; ?>
          </a> 
          <?
                  }
                  else
                  {
                     echo $GLOBALS["iPrev"];
                  }
                  $nCPage = $nCurrentPage + 1;

                  echo '&nbsp;&nbsp;'.$GLOBALS["tPage"].' '.$nCPage.' '.$GLOBALS["tOf"].' '.$nPages.'&nbsp;&nbsp;';
                  if ($nCurrentPage + 1 != $nPages)
                  {
                     ?>
          <a href="m_images.php?subdir=<? echo $subdir; ?>&page=<? echo $nCurrentPage + 1; ?>"> 
          <? echo $GLOBALS["iNext"]; ?>
          </a> 
          <?
                  }
                  else
                  {
                     echo $GLOBALS["iNext"];
                  }

                  ?>
          <a href="m_images.php?subdir=<? echo $subdir; ?>&page=<? echo $nPages - 1; ?>"> 
          <? echo $GLOBALS["iLast"]; ?>
          </a> </td>
            </tr>
         </table>
      </td>
   </tr><?
} // function frmImagesHdFt()


function display_size($file_size)
{
    if ($file_size >= 1073741824)
    {
       $file_size = round($file_size / 1073741824 * 100) / 100 ."g";
    }
    elseif($file_size >= 1048576)
    {
       $file_size = round($file_size / 1048576 * 100) / 100 ."m";
    }
    elseif($file_size >= 1024)
    {
       $file_size = round($file_size / 1024 * 100) / 100 ."k";
    }
    else
    {
       $file_size = $file_size." bytes";
    }

    return $file_size;
} // function display_size()

?>

Explain your problem in detail. What do you mean by filename and foldername it doesnt array A-Z,0-9 ? Also, when posting your code, put it in [/code ] tags.[code =php][/code ] tags.

I mean... When i upload photo ( .jpg .gif .png )
such as a.jpg b.jpg c.jpg e.jpg c.jpg
it should arrange photo file
a.jpg
b.jpg
c.jpg
d.jpg
e.jpg
c.jpg
Step by step of A - Z
when upload by browser
but it arrange like this
e.jpg
a.jpg
c.jpg
d.jpg
b.jpg
not arrange a b c d e f
i want it arrange a b c d e f of file name

Sorry if my english is not good
Thank you very much
Best regards,

When you upload an image to the server, you can connect to your server through ftp, right click and arrange the files by name. What difference will it make anyway ?

I know that way about ftp.. but i would like anyone help me to fix this problem.. because i do not want someone upload by ftp...
Really thanks nv33n

I really have no clue how you can 'sort by name' when you upload an image using html file upload. What you can do is, when fetching the images from ftp, you can put all the names in an array and use sort function to sort the array.

Member Avatar for fatihpiristine

i have posted that script ages ago..

here u can view them like 6*4 or how you like
http://www.daniweb.com/forums/thread93324.html

here is the file upload code. u have to do some modifications on it.

<?php
//--------------------------------------------------------------------------------
$path = "D:\websites\mysite.com\Uploads\\";
$web = "../uploads/";
$nopic = "../images/nopic.jpg";
$ad = "add_item";
$no = "1";
$page = $ad.$no;
//--------------------------------------------------------------------------------
$isim = $_REQUEST['NewsID'];
$tip = $_FILES[img1][type];
$size = $_FILES[img1][size];
//--------------------------------------------------------------------------------
$Edit = $_COOKIE['Edit'.$no];
if($Edit != "")
{
$GetID = "select * from news where NewsID='" . $isim . "'";
$FindID=mysql_query($GetID);
while($WriteID = mysql_fetch_array($FindID))
{
	if($WriteID['Resim'.$no] != "")
	{
	setcookie('Edit'.$no,'');
	$dosya = $WriteID['Resim'.$no];
	}
	else
	{
	setcookie('Edit'.$no,'');
	$dosya = $nopic;
	}
}
}
//--------------------------------------------------------------------------------
elseif($size >= 150000)
{
	$dosya = $nopic;
	//Temizle
	$sil1 = $isim."_".$no.".jpg";
	$sil2 = $isim."_".$no.".png";
	$sil3 = $isim."_".$no.".gif";
	@unlink($path.$sil1);
	@unlink($path.$sil2);
	@unlink($path.$sil3);
	$uyari = "<small>Max 150Kb</small>";
}
//--------------------------------------------------------------------------------
elseif($tip == "image/jpeg" || $tip == "image/pjpeg")
{
	$dosya = $isim."_".$no.".jpg";
	//Temizle
	$sil1 = $isim."_".$no.".jpg";
	$sil2 = $isim."_".$no.".png";
	$sil3 = $isim."_".$no.".gif";
	@unlink($path.$sil1);
	@unlink($path.$sil2);
	@unlink($path.$sil3);
	// Veritabanina Yaz
	$query = "update news set Resim". $no ." ='" . $dosya . "' where NewsID=". $isim ."";
	mysql_query($query) or die(mysql_error());
	//Kopyala
	@copy($_FILES[img1][tmp_name],$path.$dosya);

}
//--------------------------------------------------------------------------------
elseif($tip == "image/png" || $tip == "image/x-png")
{
	$dosya = $isim."_".$no.".png";
	//Temizle
	$sil1 = $isim."_".$no.".jpg";
	$sil2 = $isim."_".$no.".png";
	$sil3 = $isim."_".$no.".gif";
	@unlink($path.$sil1);
	@unlink($path.$sil2);
	@unlink($path.$sil3);
	// Veritabanina Yaz
	$query = "update news set Resim". $no ." ='" . $dosya . "' where NewsID=". $isim ."";
	mysql_query($query) or die(mysql_error());
	//Kopyala
	@copy($_FILES[img1][tmp_name],$path.$dosya);
}
//--------------------------------------------------------------------------------
elseif($tip == "image/gif")
{
	$dosya = $isim."_".$no.".gif";
	//Temizle
	$sil1 = $isim."_".$no.".jpg";
	$sil2 = $isim."_".$no.".png";
	$sil3 = $isim."_".$no.".gif";
	@unlink($path.$sil1);
	@unlink($path.$sil2);
	@unlink($path.$sil3);
	// Veritabanina Yaz
	$query = "update news set Resim". $no ." ='" . $dosya . "' where NewsID=". $isim ."";
	mysql_query($query) or die(mysql_error());
	//Kopyala
	@copy($_FILES[img1][tmp_name],$path.$dosya);
}
//--------------------------------------------------------------------------------
elseif($tip == "" )
{
	$dosya = $nopic;
}
//--------------------------------------------------------------------------------
elseif($tip != "image/jpeg" || $tip != "image/pjpeg" || $tip != "image/png" || $tip != "image/x-png" || $tip != "image/gif" || $tip != "")
{
	$dosya = $nopic;
	$uyari = "<small>Geçersiz format</small>";
}
//--------------------------------------------------------------------------------
?>
<?php
$Delete = $_GET['Delete'];
$FileName = $_GET['FileName'];
if($Delete == "OK")
{
	// Veritabanindan Sil
	$query = "update news set Resim". $no ." ='' where NewsID=". $isim ."";
	mysql_query($query) or die(mysql_error());
	@unlink($path.$FileName);
	$dosya = $nopic;
}
?>
<html>
<script language=JavaScript src='../js/controls.js'></script>
<script language="javascript">
// resim yuklemede loading resmi gosterme
document.write('<div id="loading"><table align="center" border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td align="center" height="100%"><br><img src="../images/loading.gif" alt="" align="middle"><br>Lütfen bekleyin...</td></tr></table></div>');

window.onload=function()
{
	document.getElementById("loading").style.display="none";
}
</script>
<body topmargin="0" leftmargin="0">
<form  method="post" action="<?php print $page ?>.php" enctype="multipart/form-data">
<table width="90" border="0" cellspacing="0" cellpadding="0">
<tr>
	<td align="center">
	<img name="img1" src="<?php if($dosya == $nopic) { print $dosya; } else { print $web.$dosya; } ?>" width="85" height="85">
	<?php if($dosya != $nopic) { $_POST[$dosya]; print "<br><a onclick='return resim_sil()' href=$page.php?Delete=OK&FileName=$dosya>Resmi Sil</a>&nbsp;"; } ?>
	<?php if($dosya == $nopic) { print $uyari;} ?>&nbsp;<br>
	</td>
</tr>
<tr>
<td>
<input type="file" name="img1"  accept="image/gif,image/jpeg,image/png" onChange="LimitAttach(this.form, this.form.img1.value)" size="1" style="width:80; border:none;">
</td>
</tr>
</table>
</form>
</body>
</html>

btw file names depends on NewID, which means there should be an ID posted from somewhere.
i hope you gonna understand it :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.