Plugins
Some troubles with an uploader plugin's variable

I'm trying to grate a pluging that allow users to upload files on my forum, the same plugin have script to retrieve a directory files as



I'm trying to grate a pluging that allow users to upload files on my forum, the same plugin have script to retrieve a directory files as store. Here is the full code ```` <?php  $targetfolder = "www.agrodesk.esy.es/sites/default/plugins/uploader/";  $targetfolder = $targetfolder . basename( $_FILES['file']['name']) ;  $ok=1; $file_type=$_FILES['file']['type']; if ($file_type=="application/pdf" || $file_type=="audio/mp3" || $file_type=="video/mp4" || $file_type=="image/gif" || $file_type=="image/jpeg") {  if(move_uploaded_file($_FILES['file']['tmp_name'], $targetfolder))  {  echo "Votre fichier ". basename( $_FILES['file']['name']). " a été mis en ligne avec succès!";  }  else {  echoh"Problème lors de la mise en ligne";  } } else {  echo "Vous ne pouvez uploader que des fichiers MP3s, MP4s, PDFs, JPEGs ou GIF.<br>"; } ?> <!doctype html> <html> <head> <meta charset="UTF-8"> <link rel="shortcut icon" href="./.favicon.ico"> <title>Banque de tutoriels AgroDesk</title> <link rel="stylesheet" href="./.style.css"> <script src="./.sorttable.js"></script> </head> <body> <div id="container"> <h1>Banque de tutoriels AgroDesk</h1> <table class="sortable"> <thead> <tr> <th>Nom du fichier</th> <th>Type</th> <th>Taille</th> <th>Date de mise en ligne</th> </tr> </thead> <tbody><?php // Adds pretty filesizes function pretty_filesize($file) { $size=filesize($file); if($size<1024){$size=$size." Bytes";} elseif(($size<1048576)&&($size>1023)){$size=round($size/1024, 1)." KB";} elseif(($size<1073741824)&&($size>1048575)){$size=round($size/1048576, 1)." MB";} else{$size=round($size/1073741824, 1)." GB";} return $size; } // Checks to see if veiwing hidden files is enabled if($_SERVER['QUERY_STRING']=="hidden") {$hide=""; $ahref="./"; $atext="Hide";} else {$hide="."; $ahref="./?hidden"; $atext="Show";} // Opens directory $myDirectory=opendir("."); // Gets each entry while($entryName=readdir($myDirectory)) { $dirArray[]=$entryName; } // Closes directory closedir($myDirectory); // Counts elements in array $indexCount=count($dirArray); // Sorts files sort($dirArray); // Loops through the array of files for($index=0; $index < $indexCount; $index++) { // Decides if hidden files should be displayed, based on query above. if(substr("$dirArray[$index]", 0, 1)!=$hide) { // Resets Variables $favicon=""; $class="file"; // Gets File Names $name=$dirArray[$index]; $namehref=$dirArray[$index]; // Gets Date Modified $modtime=date("M j Y g:i A", filemtime($dirArray[$index])); $timekey=date("YmdHis", filemtime($dirArray[$index])); // Separates directories, and performs operations on those directories if(is_dir($dirArray[$index])) { $extn="<Directory>"; $size="<Directory>"; $sizekey="0"; $class="dir"; // Gets favicon.ico, and displays it, only if it exists. if(file_exists("$namehref/favicon.ico")) { $favicon=" style='background-image:url($namehref/favicon.ico);'"; $extn="<Website>"; } // Cleans up . and .. directories if($name=="."){$name=". (Current Directory)"; $extn="<System Dir>"; $favicon=" style='background-image:url($namehref/.favicon.ico);'";} if($name==".."){$name=".. (Parent Directory)"; $extn="<System Dir>";} } // File-only operations else{ // Gets file extension $extn=pathinfo($dirArray[$index], PATHINFO_EXTENSION); // Prettifies file type switch ($extn){ case "png": $extn="PNG Image"; break; case "jpg": $extn="JPEG Image"; break; case "jpeg": $extn="JPEG Image"; break; case "svg": $extn="SVG Image"; break; case "gif": $extn="GIF Image"; break; case "ico": $extn="Windows Icon"; break; case "txt": $extn="Text File"; break; case "log": $extn="Log File"; break; case "htm": $extn="HTML File"; break; case "html": $extn="HTML File"; break; case "xhtml": $extn="HTML File"; break; case "shtml": $extn="HTML File"; break; case "js": $extn="Javascript File"; break; case "css": $extn="Stylesheet"; break; case "pdf": $extn="PDF Document"; break; case "xls": $extn="Spreadsheet"; break; case "xlsx": $extn="Spreadsheet"; break; case "doc": $extn="Microsoft Word Document"; break; case "docx": $extn="Microsoft Word Document"; break; case "zip": $extn="ZIP Archive"; break; case "htaccess": $extn="Apache Config File"; break; case "exe": $extn="Windows Executable"; break; default: if($extn!=""){$extn=strtoupper($extn)." File";} else{$extn="Unknown";} break; } // Gets and cleans up file size $size=pretty_filesize($dirArray[$index]); $sizekey=filesize($dirArray[$index]); } // Output echo(" <tr class='$class'> <td><a href='./$namehref'$favicon class='name'>$name</a></td> <td><a href='./$namehref'>$extn</a></td> <td sorttable_customkey='$sizekey'><a href='./$namehref'>$size</a></td> <td sorttable_customkey='$timekey'><a href='./$namehref'>$modtime</a></td> </tr>"); } } ?> </tbody> </table> </div> </body> </html> ```` I sometimes got this kind of error with all variables of upload script ```` Parse error: syntax error, unexpected '$targetfolder' (T_VARIABLE) in /home/u109713535/public_html/sites/default/plugins/uploader/uploader.php on line 3 Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 2006 MySQL server has gone away' in ```` But when i just use the script to retrieve the contain of my store directory (code bellow), everything is ok and i can acces to my site ```` <!doctype html> <html> <head> <meta charset="UTF-8"> <link rel="shortcut icon" href="./.favicon.ico"> <title>Banque de tutoriels AgroDesk</title> <link rel="stylesheet" href="./.style.css"> <script src="./.sorttable.js"></script> </head> <body> <div id="container"> <h1>Banque de tutoriels AgroDesk</h1> <table class="sortable"> <thead> <tr> <th>Nom du fichier</th> <th>Type</th> <th>Taille</th> <th>Date de mise en ligne</th> </tr> </thead> <tbody><?php // Adds pretty filesizes function pretty_filesize($file) { $size=filesize($file); if($size<1024){$size=$size." Bytes";} elseif(($size<1048576)&&($size>1023)){$size=round($size/1024, 1)." KB";} elseif(($size<1073741824)&&($size>1048575)){$size=round($size/1048576, 1)." MB";} else{$size=round($size/1073741824, 1)." GB";} return $size; } // Checks to see if veiwing hidden files is enabled if($_SERVER['QUERY_STRING']=="hidden") {$hide=""; $ahref="./"; $atext="Hide";} else {$hide="."; $ahref="./?hidden"; $atext="Show";} // Opens directory $myDirectory=opendir("."); // Gets each entry while($entryName=readdir($myDirectory)) { $dirArray[]=$entryName; } // Closes directory closedir($myDirectory); // Counts elements in array $indexCount=count($dirArray); // Sorts files sort($dirArray); // Loops through the array of files for($index=0; $index < $indexCount; $index++) { // Decides if hidden files should be displayed, based on query above. if(substr("$dirArray[$index]", 0, 1)!=$hide) { // Resets Variables $favicon=""; $class="file"; // Gets File Names $name=$dirArray[$index]; $namehref=$dirArray[$index]; // Gets Date Modified $modtime=date("M j Y g:i A", filemtime($dirArray[$index])); $timekey=date("YmdHis", filemtime($dirArray[$index])); // Separates directories, and performs operations on those directories if(is_dir($dirArray[$index])) { $extn="<Directory>"; $size="<Directory>"; $sizekey="0"; $class="dir"; // Gets favicon.ico, and displays it, only if it exists. if(file_exists("$namehref/favicon.ico")) { $favicon=" style='background-image:url($namehref/favicon.ico);'"; $extn="<Website>"; } // Cleans up . and .. directories if($name=="."){$name=". (Current Directory)"; $extn="<System Dir>"; $favicon=" style='background-image:url($namehref/.favicon.ico);'";} if($name==".."){$name=".. (Parent Directory)"; $extn="<System Dir>";} } // File-only operations else{ // Gets file extension $extn=pathinfo($dirArray[$index], PATHINFO_EXTENSION); // Prettifies file type switch ($extn){ case "png": $extn="PNG Image"; break; case "jpg": $extn="JPEG Image"; break; case "jpeg": $extn="JPEG Image"; break; case "svg": $extn="SVG Image"; break; case "gif": $extn="GIF Image"; break; case "ico": $extn="Windows Icon"; break; case "txt": $extn="Text File"; break; case "log": $extn="Log File"; break; case "htm": $extn="HTML File"; break; case "html": $extn="HTML File"; break; case "xhtml": $extn="HTML File"; break; case "shtml": $extn="HTML File"; break; case "js": $extn="Javascript File"; break; case "css": $extn="Stylesheet"; break; case "pdf": $extn="PDF Document"; break; case "xls": $extn="Spreadsheet"; break; case "xlsx": $extn="Spreadsheet"; break; case "doc": $extn="Microsoft Word Document"; break; case "docx": $extn="Microsoft Word Document"; break; case "zip": $extn="ZIP Archive"; break; case "htaccess": $extn="Apache Config File"; break; case "exe": $extn="Windows Executable"; break; default: if($extn!=""){$extn=strtoupper($extn)." File";} else{$extn="Unknown";} break; } // Gets and cleans up file size $size=pretty_filesize($dirArray[$index]); $sizekey=filesize($dirArray[$index]); } // Output echo(" <tr class='$class'> <td><a href='./$namehref'$favicon class='name'>$name</a></td> <td><a href='./$namehref'>$extn</a></td> <td sorttable_customkey='$sizekey'><a href='./$namehref'>$size</a></td> <td sorttable_customkey='$timekey'><a href='./$namehref'>$modtime</a></td> </tr>"); } } ?> </tbody> </table> </div> </body> </html> ````

Hi,

But, codoforum already allows uploading files.

And the code block is empty in your post.

Hi, But, codoforum already allows uploading files. And the code block is empty in your post.
edited Jul 27 '15 at 5:37 pm

Sorry, here is what i would post

I'm trying to create an downloading files store. The plugin allow users to upload files on the forum in specific directory and retreive the files of directory in table or files list to be download.

My script for upload don't work. How can i use codoforum to upload video, pdf, doc, docx....files

I can yet retreive the directory contain
Here is an example of what i want to do http://agrodesk.esy.es/index.php?u=/page/10/uploader

Sorry, here is what i would post I'm trying to create an downloading files store. The plugin allow users to upload files on the forum in specific directory and retreive the files of directory in table or files list to be download. My script for upload don't work. How can i use codoforum to upload video, pdf, doc, docx....files I can yet retreive the directory contain Here is an example of what i want to do http://agrodesk.esy.es/index.php?u=/page/10/uploader

Here is the code that allow the uploading file into specific directory, but i prefer to not use this one and use codoforum's plugin

<?php

 $targetfolder = "www.agrodesk.esy.es/agro_upload/";

 $targetfolder = $targetfolder . basename( $_FILES['file']['name']) ;

 $ok=1;

$file_type=$_FILES['file']['type'];

if ($file_type=="application/pdf" || $file_type=="audio/mp3" || $file_type=="video/mp4" || $file_type=="image/gif" || $file_type=="image/jpeg") {

 if(move_uploaded_file($_FILES['file']['tmp_name'], $targetfolder))

 {

 echo "Votre fichier ". basename( $_FILES['file']['name']). " a été mis en ligne avec succès!";

 }

 else {

 echoh"Problème lors de la mise en ligne";

 }

}

else {

 echo "Vous ne pouvez uploader que des fichiers MP3s, MP4s, PDFs, JPEGs ou GIF.<br>";

}

?

Here is code to retreive a directory contain:

<!doctype html>
<html>
<head>
   <meta charset="UTF-8">
   <link rel="shortcut icon" href="./.favicon.ico">
   <title>Banque de tutoriels AgroDesk</title>

   <link rel="stylesheet" href="./.style.css">
   <script src="./.sorttable.js"></script>
</head>

<body>
<div id="container">
    <h1>Banque de tutoriels AgroDesk</h1>








    <table class="sortable">
        <thead>
        <tr>
            <th>Nom du fichier</th>
            <th>Type</th>
            <th>Taille</th>
            <th>Date de mise en ligne</th>
        </tr>
        </thead>
        <tbody><?php

    // Adds pretty filesizes
    function pretty_filesize($file) {
        $size=filesize($file);
        if($size<1024){$size=$size." Bytes";}
        elseif(($size<1048576)&&($size>1023)){$size=round($size/1024, 1)." KB";}
        elseif(($size<1073741824)&&($size>1048575)){$size=round($size/1048576, 1)." MB";}
        else{$size=round($size/1073741824, 1)." GB";}
        return $size;
    }

     // Checks to see if veiwing hidden files is enabled
    if($_SERVER['QUERY_STRING']=="hidden")
    {$hide="";
     $ahref="./";
     $atext="Hide";}
    else
    {$hide=".";
     $ahref="./?hidden";
     $atext="Show";}

     // Opens directory
     $myDirectory=opendir(".");

    // Gets each entry
    while($entryName=readdir($myDirectory)) {
       $dirArray[]=$entryName;
    }

    // Closes directory
    closedir($myDirectory);

    // Counts elements in array
    $indexCount=count($dirArray);

    // Sorts files
    sort($dirArray);

    // Loops through the array of files
    for($index=0; $index < $indexCount; $index++) {

    // Decides if hidden files should be displayed, based on query above.
        if(substr("$dirArray[$index]", 0, 1)!=$hide) {

    // Resets Variables
        $favicon="";
        $class="file";

    // Gets File Names
        $name=$dirArray[$index];
        $namehref=$dirArray[$index];

    // Gets Date Modified
        $modtime=date("M j Y g:i A", filemtime($dirArray[$index]));
        $timekey=date("YmdHis", filemtime($dirArray[$index]));


    // Separates directories, and performs operations on those directories
        if(is_dir($dirArray[$index]))
        {
                $extn="&lt;Directory&gt;";
                $size="&lt;Directory&gt;";
                $sizekey="0";
                $class="dir";

            // Gets favicon.ico, and displays it, only if it exists.
                if(file_exists("$namehref/favicon.ico"))
                    {
                        $favicon=" style='background-image:url($namehref/favicon.ico);'";
                        $extn="&lt;Website&gt;";
                    }

            // Cleans up . and .. directories
                if($name=="."){$name=". (Current Directory)"; $extn="&lt;System Dir&gt;"; $favicon=" style='background-image:url($namehref/.favicon.ico);'";}
                if($name==".."){$name=".. (Parent Directory)"; $extn="&lt;System Dir&gt;";}
        }

    // File-only operations
        else{
            // Gets file extension
            $extn=pathinfo($dirArray[$index], PATHINFO_EXTENSION);

            // Prettifies file type
            switch ($extn){
                case "png": $extn="PNG Image"; break;
                case "jpg": $extn="JPEG Image"; break;
                case "jpeg": $extn="JPEG Image"; break;
                case "svg": $extn="SVG Image"; break;
                case "gif": $extn="GIF Image"; break;
                case "ico": $extn="Windows Icon"; break;

                case "txt": $extn="Text File"; break;
                case "log": $extn="Log File"; break;
                case "htm": $extn="HTML File"; break;
                case "html": $extn="HTML File"; break;
                case "xhtml": $extn="HTML File"; break;
                case "shtml": $extn="HTML File"; break;
                case "js": $extn="Javascript File"; break;
                case "css": $extn="Stylesheet"; break;

                case "pdf": $extn="PDF Document"; break;
                case "xls": $extn="Spreadsheet"; break;
                case "xlsx": $extn="Spreadsheet"; break;
                case "doc": $extn="Microsoft Word Document"; break;
                case "docx": $extn="Microsoft Word Document"; break;

                case "zip": $extn="ZIP Archive"; break;
                case "htaccess": $extn="Apache Config File"; break;
                case "exe": $extn="Windows Executable"; break;

                default: if($extn!=""){$extn=strtoupper($extn)." File";} else{$extn="Unknown";} break;
            }

            // Gets and cleans up file size
                $size=pretty_filesize($dirArray[$index]);
                $sizekey=filesize($dirArray[$index]);
        }

    // Output
     echo("
        <tr class='$class'>
            <td><a href='./$namehref'$favicon class='name'>$name</a></td>
            <td><a href='./$namehref'>$extn</a></td>
            <td sorttable_customkey='$sizekey'><a href='./$namehref'>$size</a></td>
            <td sorttable_customkey='$timekey'><a href='./$namehref'>$modtime</a></td>
        </tr>");
       }
    }
    ?>

        </tbody>
    </table>

</div>
</body>
</html>
Here is the code that allow the uploading file into specific directory, but i prefer to not use this one and use codoforum&#039;s plugin ```` &amp;lt;?php &amp;nbsp;$targetfolder = &quot;www.agrodesk.esy.es/agro_upload/&quot;; &amp;nbsp;$targetfolder = $targetfolder . basename( $_FILES[&#039;file&#039;][&#039;name&#039;]) ; &amp;nbsp;$ok=1; $file_type=$_FILES[&#039;file&#039;][&#039;type&#039;]; if ($file_type==&quot;application/pdf&quot; || $file_type==&quot;audio/mp3&quot; || $file_type==&quot;video/mp4&quot; || $file_type==&quot;image/gif&quot; || $file_type==&quot;image/jpeg&quot;) { &amp;nbsp;if(move_uploaded_file($_FILES[&#039;file&#039;][&#039;tmp_name&#039;], $targetfolder)) &amp;nbsp;{ &amp;nbsp;echo &quot;Votre fichier &quot;. basename( $_FILES[&#039;file&#039;][&#039;name&#039;]). &quot; a &amp;eacute;t&amp;eacute; mis en ligne avec succ&amp;egrave;s!&quot;; &amp;nbsp;} &amp;nbsp;else { &amp;nbsp;echoh&quot;Probl&amp;egrave;me lors de la mise en ligne&quot;; &amp;nbsp;} } else { &amp;nbsp;echo &quot;Vous ne pouvez uploader que des fichiers MP3s, MP4s, PDFs, JPEGs ou GIF.&amp;lt;br&amp;gt;&quot;; } ? ```` Here is code to retreive a directory contain: ```` &amp;lt;!doctype html&amp;gt; &amp;lt;html&amp;gt; &amp;lt;head&amp;gt; &amp;lt;meta charset=&quot;UTF-8&quot;&amp;gt; &amp;lt;link rel=&quot;shortcut icon&quot; href=&quot;./.favicon.ico&quot;&amp;gt; &amp;lt;title&amp;gt;Banque de tutoriels AgroDesk&amp;lt;/title&amp;gt; &amp;lt;link rel=&quot;stylesheet&quot; href=&quot;./.style.css&quot;&amp;gt; &amp;lt;script src=&quot;./.sorttable.js&quot;&amp;gt;&amp;lt;/script&amp;gt; &amp;lt;/head&amp;gt; &amp;lt;body&amp;gt; &amp;lt;div id=&quot;container&quot;&amp;gt; &amp;lt;h1&amp;gt;Banque de tutoriels AgroDesk&amp;lt;/h1&amp;gt; &amp;lt;table class=&quot;sortable&quot;&amp;gt; &amp;lt;thead&amp;gt; &amp;lt;tr&amp;gt; &amp;lt;th&amp;gt;Nom du fichier&amp;lt;/th&amp;gt; &amp;lt;th&amp;gt;Type&amp;lt;/th&amp;gt; &amp;lt;th&amp;gt;Taille&amp;lt;/th&amp;gt; &amp;lt;th&amp;gt;Date de mise en ligne&amp;lt;/th&amp;gt; &amp;lt;/tr&amp;gt; &amp;lt;/thead&amp;gt; &amp;lt;tbody&amp;gt;&amp;lt;?php // Adds pretty filesizes function pretty_filesize($file) { $size=filesize($file); if($size&amp;lt;1024){$size=$size.&quot; Bytes&quot;;} elseif(($size&amp;lt;1048576)&amp;amp;&amp;amp;($size&amp;gt;1023)){$size=round($size/1024, 1).&quot; KB&quot;;} elseif(($size&amp;lt;1073741824)&amp;amp;&amp;amp;($size&amp;gt;1048575)){$size=round($size/1048576, 1).&quot; MB&quot;;} else{$size=round($size/1073741824, 1).&quot; GB&quot;;} return $size; } // Checks to see if veiwing hidden files is enabled if($_SERVER[&#039;QUERY_STRING&#039;]==&quot;hidden&quot;) {$hide=&quot;&quot;; $ahref=&quot;./&quot;; $atext=&quot;Hide&quot;;} else {$hide=&quot;.&quot;; $ahref=&quot;./?hidden&quot;; $atext=&quot;Show&quot;;} // Opens directory $myDirectory=opendir(&quot;.&quot;); // Gets each entry while($entryName=readdir($myDirectory)) { $dirArray[]=$entryName; } // Closes directory closedir($myDirectory); // Counts elements in array $indexCount=count($dirArray); // Sorts files sort($dirArray); // Loops through the array of files for($index=0; $index &amp;lt; $indexCount; $index++) { // Decides if hidden files should be displayed, based on query above. if(substr(&quot;$dirArray[$index]&quot;, 0, 1)!=$hide) { // Resets Variables $favicon=&quot;&quot;; $class=&quot;file&quot;; // Gets File Names $name=$dirArray[$index]; $namehref=$dirArray[$index]; // Gets Date Modified $modtime=date(&quot;M j Y g:i A&quot;, filemtime($dirArray[$index])); $timekey=date(&quot;YmdHis&quot;, filemtime($dirArray[$index])); // Separates directories, and performs operations on those directories if(is_dir($dirArray[$index])) { $extn=&quot;&amp;amp;lt;Directory&amp;amp;gt;&quot;; $size=&quot;&amp;amp;lt;Directory&amp;amp;gt;&quot;; $sizekey=&quot;0&quot;; $class=&quot;dir&quot;; // Gets favicon.ico, and displays it, only if it exists. if(file_exists(&quot;$namehref/favicon.ico&quot;)) { $favicon=&quot; style=&#039;background-image:url($namehref/favicon.ico);&#039;&quot;; $extn=&quot;&amp;amp;lt;Website&amp;amp;gt;&quot;; } // Cleans up . and .. directories if($name==&quot;.&quot;){$name=&quot;. (Current Directory)&quot;; $extn=&quot;&amp;amp;lt;System Dir&amp;amp;gt;&quot;; $favicon=&quot; style=&#039;background-image:url($namehref/.favicon.ico);&#039;&quot;;} if($name==&quot;..&quot;){$name=&quot;.. (Parent Directory)&quot;; $extn=&quot;&amp;amp;lt;System Dir&amp;amp;gt;&quot;;} } // File-only operations else{ // Gets file extension $extn=pathinfo($dirArray[$index], PATHINFO_EXTENSION); // Prettifies file type switch ($extn){ case &quot;png&quot;: $extn=&quot;PNG Image&quot;; break; case &quot;jpg&quot;: $extn=&quot;JPEG Image&quot;; break; case &quot;jpeg&quot;: $extn=&quot;JPEG Image&quot;; break; case &quot;svg&quot;: $extn=&quot;SVG Image&quot;; break; case &quot;gif&quot;: $extn=&quot;GIF Image&quot;; break; case &quot;ico&quot;: $extn=&quot;Windows Icon&quot;; break; case &quot;txt&quot;: $extn=&quot;Text File&quot;; break; case &quot;log&quot;: $extn=&quot;Log File&quot;; break; case &quot;htm&quot;: $extn=&quot;HTML File&quot;; break; case &quot;html&quot;: $extn=&quot;HTML File&quot;; break; case &quot;xhtml&quot;: $extn=&quot;HTML File&quot;; break; case &quot;shtml&quot;: $extn=&quot;HTML File&quot;; break; case &quot;js&quot;: $extn=&quot;Javascript File&quot;; break; case &quot;css&quot;: $extn=&quot;Stylesheet&quot;; break; case &quot;pdf&quot;: $extn=&quot;PDF Document&quot;; break; case &quot;xls&quot;: $extn=&quot;Spreadsheet&quot;; break; case &quot;xlsx&quot;: $extn=&quot;Spreadsheet&quot;; break; case &quot;doc&quot;: $extn=&quot;Microsoft Word Document&quot;; break; case &quot;docx&quot;: $extn=&quot;Microsoft Word Document&quot;; break; case &quot;zip&quot;: $extn=&quot;ZIP Archive&quot;; break; case &quot;htaccess&quot;: $extn=&quot;Apache Config File&quot;; break; case &quot;exe&quot;: $extn=&quot;Windows Executable&quot;; break; default: if($extn!=&quot;&quot;){$extn=strtoupper($extn).&quot; File&quot;;} else{$extn=&quot;Unknown&quot;;} break; } // Gets and cleans up file size $size=pretty_filesize($dirArray[$index]); $sizekey=filesize($dirArray[$index]); } // Output echo(&quot; &amp;lt;tr class=&#039;$class&#039;&amp;gt; &amp;lt;td&amp;gt;&amp;lt;a href=&#039;./$namehref&#039;$favicon class=&#039;name&#039;&amp;gt;$name&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt; &amp;lt;td&amp;gt;&amp;lt;a href=&#039;./$namehref&#039;&amp;gt;$extn&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt; &amp;lt;td sorttable_customkey=&#039;$sizekey&#039;&amp;gt;&amp;lt;a href=&#039;./$namehref&#039;&amp;gt;$size&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt; &amp;lt;td sorttable_customkey=&#039;$timekey&#039;&amp;gt;&amp;lt;a href=&#039;./$namehref&#039;&amp;gt;$modtime&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt; &amp;lt;/tr&amp;gt;&quot;); } } ?&amp;gt; &amp;lt;/tbody&amp;gt; &amp;lt;/table&amp;gt; &amp;lt;/div&amp;gt; &amp;lt;/body&amp;gt; &amp;lt;/html&amp;gt; ````

Hi,

You can use following method to upload file


\CODOF\File\Upload::save($_FILES['file'], $filename, $folder, 0777);

//$filename is name of file
//$folder is where the files will be stored

You can have a look at the upload code in sys/Controller/Ajax/forum/topic.php, around line 208

Hi, You can use following method to upload file ``` \CODOF\File\Upload::save($_FILES[&#039;file&#039;], $filename, $folder, 0777); //$filename is name of file //$folder is where the files will be stored ``` You can have a look at the upload code in sys/Controller/Ajax/forum/topic.php, around line 208

Morning,
Where should i write this code? in plugin file? plugin.info.php? or else.
I wrote it in both but i got error

Morning, Where should i write this code? in plugin file? plugin.info.php? or else. I wrote it in both but i got error

Hi,

In the plugin file .

Make sure you test $_FILES['file'] exists with isset.

Hi, In the plugin file . Make sure you test $_FILES[&#039;file&#039;] exists with isset.

Hi Mr Adesh, i'm not sure to have well done all thang, i got my plugin folder file sorting but don't have the button to allow the file selecting....then uploading.
Sorry, i'm not good at all with php...
Here is my code

<!doctype html>
<html>
<head>
   <meta charset="UTF-8">
   <link rel="shortcut icon" href="./.favicon.ico">
   <title>Banque de tutoriels AgroDesk</title>

   <link rel="stylesheet" href="./.style.css">
   <script src="./.sorttable.js"></script>
</head>

<body>
<div id="container">
    <h1>Banque de tutoriels AgroDesk</h1>


    <?php
    function upload() {

        if (!isset($_FILES)) {
            return;
        }
        $errors = array();
        $file_info = array();

        if (is_array($_FILES['file']['name'])) {

            $images = \CODOF\Util::re_array_files($_FILES['file']);
        } else {

            $images = array($_FILES['file']);
        }


        foreach ($images as $image) {
            if (
                    !\CODOF\File\Upload::valid($image) OR ! \CODOF\File\Upload::not_empty($image) OR ! \CODOF\File\Upload::size($image, (int) \CODOF\Util::get_opt('forum_attachments_size')) OR ! \CODOF\File\Upload::type($image, explode(",", \CODOF\Util::get_opt('forum_attachments_exts')))) {
                $errors[] = "Error While uploading the image.";
            } else {

                $ext = strtolower(pathinfo($image['name'], PATHINFO_EXTENSION));
                $file_info[] = \CODOF\File\Upload::save($image, uniqid() . "." . $ext, DATA_PATH . \CODOF\Util::get_opt('forum_attachments_path'), 0777);
            }
        }

        echo json_encode($file_info);
    }


?>






    <table class="sortable">
        <thead>
        <tr>
            <th>Nom du fichier</th>
            <th>Type</th>
            <th>Taille</th>
            <th>Date de mise en ligne</th>
        </tr>
        </thead>
        <tbody><?php





    // Adds pretty filesizes
    function pretty_filesize($file) {
        $size=filesize($file);
        if($size<1024){$size=$size." Bytes";}
        elseif(($size<1048576)&&($size>1023)){$size=round($size/1024, 1)." KB";}
        elseif(($size<1073741824)&&($size>1048575)){$size=round($size/1048576, 1)." MB";}
        else{$size=round($size/1073741824, 1)." GB";}
        return $size;
    }

     // Checks to see if veiwing hidden files is enabled
    if($_SERVER['QUERY_STRING']=="hidden")
    {$hide="";
     $ahref="./";
     $atext="Hide";}
    else
    {$hide=".";
     $ahref="./?hidden";
     $atext="Show";}

     // Opens directory
     $myDirectory=opendir(".");

    // Gets each entry
    while($entryName=readdir($myDirectory)) {
       $dirArray[]=$entryName;
    }

    // Closes directory
    closedir($myDirectory);

    // Counts elements in array
    $indexCount=count($dirArray);

    // Sorts files
    sort($dirArray);

    // Loops through the array of files
    for($index=0; $index < $indexCount; $index++) {

    // Decides if hidden files should be displayed, based on query above.
        if(substr("$dirArray[$index]", 0, 1)!=$hide) {

    // Resets Variables
        $favicon="";
        $class="file";

    // Gets File Names
        $name=$dirArray[$index];
        $namehref=$dirArray[$index];

    // Gets Date Modified
        $modtime=date("M j Y g:i A", filemtime($dirArray[$index]));
        $timekey=date("YmdHis", filemtime($dirArray[$index]));


    // Separates directories, and performs operations on those directories
        if(is_dir($dirArray[$index]))
        {
                $extn="&lt;Directory&gt;";
                $size="&lt;Directory&gt;";
                $sizekey="0";
                $class="dir";

            // Gets favicon.ico, and displays it, only if it exists.
                if(file_exists("$namehref/favicon.ico"))
                    {
                        $favicon=" style='background-image:url($namehref/favicon.ico);'";
                        $extn="&lt;Website&gt;";
                    }

            // Cleans up . and .. directories
                if($name=="."){$name=". (Current Directory)"; $extn="&lt;System Dir&gt;"; $favicon=" style='background-image:url($namehref/.favicon.ico);'";}
                if($name==".."){$name=".. (Parent Directory)"; $extn="&lt;System Dir&gt;";}
        }

    // File-only operations
        else{
            // Gets file extension
            $extn=pathinfo($dirArray[$index], PATHINFO_EXTENSION);

            // Prettifies file type
            switch ($extn){
                case "png": $extn="PNG Image"; break;
                case "jpg": $extn="JPEG Image"; break;
                case "jpeg": $extn="JPEG Image"; break;
                case "svg": $extn="SVG Image"; break;
                case "gif": $extn="GIF Image"; break;
                case "ico": $extn="Windows Icon"; break;

                case "txt": $extn="Text File"; break;
                case "log": $extn="Log File"; break;
                case "htm": $extn="HTML File"; break;
                case "html": $extn="HTML File"; break;
                case "xhtml": $extn="HTML File"; break;
                case "shtml": $extn="HTML File"; break;
                case "js": $extn="Javascript File"; break;
                case "css": $extn="Stylesheet"; break;

                case "pdf": $extn="PDF Document"; break;
                case "xls": $extn="Spreadsheet"; break;
                case "xlsx": $extn="Spreadsheet"; break;
                case "doc": $extn="Microsoft Word Document"; break;
                case "docx": $extn="Microsoft Word Document"; break;

                case "zip": $extn="ZIP Archive"; break;
                case "htaccess": $extn="Apache Config File"; break;
                case "exe": $extn="Windows Executable"; break;

                default: if($extn!=""){$extn=strtoupper($extn)." File";} else{$extn="Unknown";} break;
            }

            // Gets and cleans up file size
                $size=pretty_filesize($dirArray[$index]);
                $sizekey=filesize($dirArray[$index]);
        }

    // Output
     echo("
        <tr class='$class'>
            <td><a href='./$namehref'$favicon class='name'>$name</a></td>
            <td><a href='./$namehref'>$extn</a></td>
            <td sorttable_customkey='$sizekey'><a href='./$namehref'>$size</a></td>
            <td sorttable_customkey='$timekey'><a href='./$namehref'>$modtime</a></td>
        </tr>");
       }
    }
    ?>

        </tbody>
    </table>

</div>
</body>
</html>
Hi Mr Adesh, i&#039;m not sure to have well done all thang, i got my plugin folder file sorting but don&#039;t have the button to allow the file selecting....then uploading. Sorry, i&#039;m not good at all with php... Here is my code ```` &amp;lt;!doctype html&amp;gt; &amp;lt;html&amp;gt; &amp;lt;head&amp;gt; &amp;lt;meta charset=&quot;UTF-8&quot;&amp;gt; &amp;lt;link rel=&quot;shortcut icon&quot; href=&quot;./.favicon.ico&quot;&amp;gt; &amp;lt;title&amp;gt;Banque de tutoriels AgroDesk&amp;lt;/title&amp;gt; &amp;lt;link rel=&quot;stylesheet&quot; href=&quot;./.style.css&quot;&amp;gt; &amp;lt;script src=&quot;./.sorttable.js&quot;&amp;gt;&amp;lt;/script&amp;gt; &amp;lt;/head&amp;gt; &amp;lt;body&amp;gt; &amp;lt;div id=&quot;container&quot;&amp;gt; &amp;lt;h1&amp;gt;Banque de tutoriels AgroDesk&amp;lt;/h1&amp;gt; &amp;lt;?php function upload() { if (!isset($_FILES)) { return; } $errors = array(); $file_info = array(); if (is_array($_FILES[&#039;file&#039;][&#039;name&#039;])) { $images = \CODOF\Util::re_array_files($_FILES[&#039;file&#039;]); } else { $images = array($_FILES[&#039;file&#039;]); } foreach ($images as $image) { if ( !\CODOF\File\Upload::valid($image) OR ! \CODOF\File\Upload::not_empty($image) OR ! \CODOF\File\Upload::size($image, (int) \CODOF\Util::get_opt(&#039;forum_attachments_size&#039;)) OR ! \CODOF\File\Upload::type($image, explode(&quot;,&quot;, \CODOF\Util::get_opt(&#039;forum_attachments_exts&#039;)))) { $errors[] = &quot;Error While uploading the image.&quot;; } else { $ext = strtolower(pathinfo($image[&#039;name&#039;], PATHINFO_EXTENSION)); $file_info[] = \CODOF\File\Upload::save($image, uniqid() . &quot;.&quot; . $ext, DATA_PATH . \CODOF\Util::get_opt(&#039;forum_attachments_path&#039;), 0777); } } echo json_encode($file_info); } ?&amp;gt; &amp;lt;table class=&quot;sortable&quot;&amp;gt; &amp;lt;thead&amp;gt; &amp;lt;tr&amp;gt; &amp;lt;th&amp;gt;Nom du fichier&amp;lt;/th&amp;gt; &amp;lt;th&amp;gt;Type&amp;lt;/th&amp;gt; &amp;lt;th&amp;gt;Taille&amp;lt;/th&amp;gt; &amp;lt;th&amp;gt;Date de mise en ligne&amp;lt;/th&amp;gt; &amp;lt;/tr&amp;gt; &amp;lt;/thead&amp;gt; &amp;lt;tbody&amp;gt;&amp;lt;?php // Adds pretty filesizes function pretty_filesize($file) { $size=filesize($file); if($size&amp;lt;1024){$size=$size.&quot; Bytes&quot;;} elseif(($size&amp;lt;1048576)&amp;amp;&amp;amp;($size&amp;gt;1023)){$size=round($size/1024, 1).&quot; KB&quot;;} elseif(($size&amp;lt;1073741824)&amp;amp;&amp;amp;($size&amp;gt;1048575)){$size=round($size/1048576, 1).&quot; MB&quot;;} else{$size=round($size/1073741824, 1).&quot; GB&quot;;} return $size; } // Checks to see if veiwing hidden files is enabled if($_SERVER[&#039;QUERY_STRING&#039;]==&quot;hidden&quot;) {$hide=&quot;&quot;; $ahref=&quot;./&quot;; $atext=&quot;Hide&quot;;} else {$hide=&quot;.&quot;; $ahref=&quot;./?hidden&quot;; $atext=&quot;Show&quot;;} // Opens directory $myDirectory=opendir(&quot;.&quot;); // Gets each entry while($entryName=readdir($myDirectory)) { $dirArray[]=$entryName; } // Closes directory closedir($myDirectory); // Counts elements in array $indexCount=count($dirArray); // Sorts files sort($dirArray); // Loops through the array of files for($index=0; $index &amp;lt; $indexCount; $index++) { // Decides if hidden files should be displayed, based on query above. if(substr(&quot;$dirArray[$index]&quot;, 0, 1)!=$hide) { // Resets Variables $favicon=&quot;&quot;; $class=&quot;file&quot;; // Gets File Names $name=$dirArray[$index]; $namehref=$dirArray[$index]; // Gets Date Modified $modtime=date(&quot;M j Y g:i A&quot;, filemtime($dirArray[$index])); $timekey=date(&quot;YmdHis&quot;, filemtime($dirArray[$index])); // Separates directories, and performs operations on those directories if(is_dir($dirArray[$index])) { $extn=&quot;&amp;amp;lt;Directory&amp;amp;gt;&quot;; $size=&quot;&amp;amp;lt;Directory&amp;amp;gt;&quot;; $sizekey=&quot;0&quot;; $class=&quot;dir&quot;; // Gets favicon.ico, and displays it, only if it exists. if(file_exists(&quot;$namehref/favicon.ico&quot;)) { $favicon=&quot; style=&#039;background-image:url($namehref/favicon.ico);&#039;&quot;; $extn=&quot;&amp;amp;lt;Website&amp;amp;gt;&quot;; } // Cleans up . and .. directories if($name==&quot;.&quot;){$name=&quot;. (Current Directory)&quot;; $extn=&quot;&amp;amp;lt;System Dir&amp;amp;gt;&quot;; $favicon=&quot; style=&#039;background-image:url($namehref/.favicon.ico);&#039;&quot;;} if($name==&quot;..&quot;){$name=&quot;.. (Parent Directory)&quot;; $extn=&quot;&amp;amp;lt;System Dir&amp;amp;gt;&quot;;} } // File-only operations else{ // Gets file extension $extn=pathinfo($dirArray[$index], PATHINFO_EXTENSION); // Prettifies file type switch ($extn){ case &quot;png&quot;: $extn=&quot;PNG Image&quot;; break; case &quot;jpg&quot;: $extn=&quot;JPEG Image&quot;; break; case &quot;jpeg&quot;: $extn=&quot;JPEG Image&quot;; break; case &quot;svg&quot;: $extn=&quot;SVG Image&quot;; break; case &quot;gif&quot;: $extn=&quot;GIF Image&quot;; break; case &quot;ico&quot;: $extn=&quot;Windows Icon&quot;; break; case &quot;txt&quot;: $extn=&quot;Text File&quot;; break; case &quot;log&quot;: $extn=&quot;Log File&quot;; break; case &quot;htm&quot;: $extn=&quot;HTML File&quot;; break; case &quot;html&quot;: $extn=&quot;HTML File&quot;; break; case &quot;xhtml&quot;: $extn=&quot;HTML File&quot;; break; case &quot;shtml&quot;: $extn=&quot;HTML File&quot;; break; case &quot;js&quot;: $extn=&quot;Javascript File&quot;; break; case &quot;css&quot;: $extn=&quot;Stylesheet&quot;; break; case &quot;pdf&quot;: $extn=&quot;PDF Document&quot;; break; case &quot;xls&quot;: $extn=&quot;Spreadsheet&quot;; break; case &quot;xlsx&quot;: $extn=&quot;Spreadsheet&quot;; break; case &quot;doc&quot;: $extn=&quot;Microsoft Word Document&quot;; break; case &quot;docx&quot;: $extn=&quot;Microsoft Word Document&quot;; break; case &quot;zip&quot;: $extn=&quot;ZIP Archive&quot;; break; case &quot;htaccess&quot;: $extn=&quot;Apache Config File&quot;; break; case &quot;exe&quot;: $extn=&quot;Windows Executable&quot;; break; default: if($extn!=&quot;&quot;){$extn=strtoupper($extn).&quot; File&quot;;} else{$extn=&quot;Unknown&quot;;} break; } // Gets and cleans up file size $size=pretty_filesize($dirArray[$index]); $sizekey=filesize($dirArray[$index]); } // Output echo(&quot; &amp;lt;tr class=&#039;$class&#039;&amp;gt; &amp;lt;td&amp;gt;&amp;lt;a href=&#039;./$namehref&#039;$favicon class=&#039;name&#039;&amp;gt;$name&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt; &amp;lt;td&amp;gt;&amp;lt;a href=&#039;./$namehref&#039;&amp;gt;$extn&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt; &amp;lt;td sorttable_customkey=&#039;$sizekey&#039;&amp;gt;&amp;lt;a href=&#039;./$namehref&#039;&amp;gt;$size&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt; &amp;lt;td sorttable_customkey=&#039;$timekey&#039;&amp;gt;&amp;lt;a href=&#039;./$namehref&#039;&amp;gt;$modtime&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt; &amp;lt;/tr&amp;gt;&quot;); } } ?&amp;gt; &amp;lt;/tbody&amp;gt; &amp;lt;/table&amp;gt; &amp;lt;/div&amp;gt; &amp;lt;/body&amp;gt; &amp;lt;/html&amp;gt; ````

, i got my plugin folder file sorting but don't have the button to allow the file selecting....then uploading.

We did not understand what you meant here.
Can you please explain ?

&amp;gt;, i got my plugin folder file sorting but don&#039;t have the button to allow the file selecting....then uploading. We did not understand what you meant here. Can you please explain ?

Hi Mr,

I have made a form used as category for uploading file with "action=submit_my_file",

I have two problems:
1/- when i submit the file, i can see that the transfert is going but it return a "page not found" in fine
2- i think that my plugin script for uploading isn't correct.

Whenever i wrote in Routes

dispatch_post('submit_my_file', function() {


    $forum = new \Controller\forum();
    $forum->category('banque-de-tutoriels', 1);
    CODOF\Smarty\Layout::load($forum->view, $forum->css_files, $forum->js_files);

});

My plugin code is copied from > sys/Controller/Ajax/forum/topic.php, around line 208> like you suggest me

   <?php
    function upload() {

        if (!isset($_FILES)) {
            return;
        }
        $errors = array();
        $file_info = array();

        if (is_array($_FILES['file']['name'])) {

            $images = \CODOF\Util::re_array_files($_FILES['file']);
        } else {

            $images = array($_FILES['file']);
        }


        foreach ($images as $image) {
            if (
                    !\CODOF\File\Upload::valid($image) OR ! \CODOF\File\Upload::not_empty($image) OR ! \CODOF\File\Upload::size($image, (int) \CODOF\Util::get_opt('forum_attachments_size')) OR ! \CODOF\File\Upload::type($image, explode(",", \CODOF\Util::get_opt('forum_attachments_exts')))) {
                $errors[] = "Error While uploading the image.";
            } else {

                $ext = strtolower(pathinfo($image['name'], PATHINFO_EXTENSION));
                $file_info[] = \CODOF\File\Upload::save($image, uniqid() . "." . $ext, DATA_PATH . \CODOF\Util::get_opt('forum_attachments_path'), 0777);
            }
        }

        echo json_encode($file_info);
    }


?>

My category.pl code for uploading is

<form action="{$smarty.const.RURI}submit_my_file" method="post" enctype="multipart/form-data">
 <input type="file" name="file" />
 <button type="submit" name="btn-upload">mettre en ligne</button>
 </form>
Hi Mr, I have made a form used as category for uploading file with &quot;action=submit_my_file&quot;, I have two problems: 1/- when i submit the file, i can see that the transfert is going but it return a &quot;page not found&quot; in fine 2- i think that my plugin script for uploading isn&#039;t correct. Whenever i wrote in Routes ```` dispatch_post(&#039;submit_my_file&#039;, function() { $forum = new \Controller\forum(); $forum-&amp;gt;category(&#039;banque-de-tutoriels&#039;, 1); CODOF\Smarty\Layout::load($forum-&amp;gt;view, $forum-&amp;gt;css_files, $forum-&amp;gt;js_files); }); ```` My plugin code is copied from &amp;gt; sys/Controller/Ajax/forum/topic.php, around line 208&amp;gt; like you suggest me ```` &amp;lt;?php function upload() { if (!isset($_FILES)) { return; } $errors = array(); $file_info = array(); if (is_array($_FILES[&#039;file&#039;][&#039;name&#039;])) { $images = \CODOF\Util::re_array_files($_FILES[&#039;file&#039;]); } else { $images = array($_FILES[&#039;file&#039;]); } foreach ($images as $image) { if ( !\CODOF\File\Upload::valid($image) OR ! \CODOF\File\Upload::not_empty($image) OR ! \CODOF\File\Upload::size($image, (int) \CODOF\Util::get_opt(&#039;forum_attachments_size&#039;)) OR ! \CODOF\File\Upload::type($image, explode(&quot;,&quot;, \CODOF\Util::get_opt(&#039;forum_attachments_exts&#039;)))) { $errors[] = &quot;Error While uploading the image.&quot;; } else { $ext = strtolower(pathinfo($image[&#039;name&#039;], PATHINFO_EXTENSION)); $file_info[] = \CODOF\File\Upload::save($image, uniqid() . &quot;.&quot; . $ext, DATA_PATH . \CODOF\Util::get_opt(&#039;forum_attachments_path&#039;), 0777); } } echo json_encode($file_info); } ?&amp;gt; ```` My category.pl code for uploading is ```` &amp;lt;form action=&quot;{$smarty.const.RURI}submit_my_file&quot; method=&quot;post&quot; enctype=&quot;multipart/form-data&quot;&amp;gt; &amp;lt;input type=&quot;file&quot; name=&quot;file&quot; /&amp;gt; &amp;lt;button type=&quot;submit&quot; name=&quot;btn-upload&quot;&amp;gt;mettre en ligne&amp;lt;/button&amp;gt; &amp;lt;/form&amp;gt; ````

Hi,

Can you provide us FTP details to your server ?

We can have a look at both the issues that you meantion in this as well as the previous topic.

Hi, Can you provide us FTP details to your server ? We can have a look at both the issues that you meantion in this as well as the previous topic.
Necessity is the mother of all inventions!

Hi Mister Yes, i can. Just provide your mail adress.
I'm just seing that it possible to upload any kind of file as topic with codoforum. So now what i'm going to ask for is if it possible to remove for just one category all new topic editing's widgets and keep just uploader's widget?
But whatever your answer provide me please your mail. Thanks before

Hi Mister Yes, i can. Just provide your mail adress. I&#039;m just seing that it possible to upload any kind of file as topic with codoforum. So now what i&#039;m going to ask for is if it possible to remove for just one category all new topic editing&#039;s widgets and keep just uploader&#039;s widget? But whatever your answer provide me please your mail. Thanks before

Hi,

You can email us at admin[@]codologic.com

Hi, You can email us at admin[@]codologic.com
Necessity is the mother of all inventions!

Hi Admin,
I would to know if it possible to remove for just one category all > new topic editing's widgets> and keep just uploader's widget?

Hi Admin, I would to know if it possible to remove for just one category all &amp;gt; new topic editing&#039;s widgets&amp;gt; and keep just uploader&#039;s widget?
522
13
4
live preview
enter atleast 10 characters
WARNING: You mentioned %MENTIONS%, but they cannot see this message and will not be notified
Saving...
Saved
With selected deselect posts show selected posts
All posts under this topic will be deleted ?
Pending draft ... Click to resume editing
Discard draft