Hello all,

I am looking for a free upload class script and I find this:

upload class

Yet, I still do not know how to use it. When I try to upload pictures file in the browser they show me bunch of codes instead showing me the file pictures and copying the file to a particular folder.

Why is it? How to use the free script?

Thanks before.

5 Years
Discussion Span
Last Post by Squidge

I run the script in localhost: C:\xampp\htdocs\class uploads\index.html

Then I test it by uploading jpg files. Then afterward bunch of codes appears. for example:



// we first include the upload class, as we will need it here to deal with the uploaded file

// retrieve eventual CLI parameters
$cli = (isset($argc) && $argc > 1);
if ($cli) {
    if (isset($argv[1])) $_GET['file'] = $argv[1];
    if (isset($argv[2])) $_GET['dir'] = $argv[2];
    if (isset($argv[3])) $_GET['pics'] = $argv[3];

// set variables
$dir_dest = (isset($_GET['dir']) ? $_GET['dir'] : 'test');
$dir_pics = (isset($_GET['pics']) ? $_GET['pics'] : $dir_dest);

if (!$cli && !(isset($_SERVER['HTTP_X_FILE_NAME']) && isset($_SERVER['CONTENT_LENGTH']))) {

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv=content-type content="text/html; charset=UTF-8">
    <title>class.php.upload test forms</title>

        body {
        p.result {

the above coding is from the sample of the download, and runs fine for me, so have you changed something in the sample?

Looking at the script it is from 2010, and aklot has changed since then.

May i ask what part of the script are you wanting to use? single upload? Multi upload? etc

Edited by Squidge

Attachments Untitled.png 213.49 KB

I want to try the single upload. How to use the script ? What's the script is for ?

No, I haven't changed anything from the sample.


have a look at the upload file from line 75 onwards, this is well documented on how this works, if you read the comments.

Use $dir_dest to set your upload directory


$dir_dest = "my_path_to\my_destination\Folder\";

// ---------- SIMPLE UPLOAD ----------

    // we create an instance of the class, giving as argument the PHP object
    // corresponding to the file field from the form
    // All the uploads are accessible from the PHP object $_FILES
    $handle = new Upload($_FILES['my_field']);

    // then we check if the file has been uploaded properly
    // in its *temporary* location in the server (often, it is /tmp)
    if ($handle->uploaded) {

        // yes, the file is on the server
        // now, we start the upload 'process'. That is, to copy the uploaded file
        // from its temporary location to the wanted location
        // It could be something like $handle->Process('/home/www/my_uploads/');

        // we check if everything went OK
        if ($handle->processed) {
            // everything was fine !
            echo '<p class="result">';
            echo '  <b>File uploaded with success</b><br />';
            echo '  File: <a href="'.$dir_pics.'/' . $handle->file_dst_name . '">' . $handle->file_dst_name . '</a>';
            echo '   (' . round(filesize($handle->file_dst_pathname)/256)/4 . 'KB)';
            echo '</p>';
        } else {
            // one error occured
            echo '<p class="result">';
            echo '  <b>File not uploaded to the wanted location</b><br />';
            echo '  Error: ' . $handle->error . '';
            echo '</p>';

        // we delete the temporary files
        $handle-> Clean();

    } else {
        // if we're here, the upload file failed for some reasons
        // i.e. the server didn't receive the file
        echo '<p class="result">';
        echo '  <b>File not uploaded on the server</b><br />';
        echo '  Error: ' . $handle->error . '';
        echo '</p>';

Edited by Squidge


Why all the codes underneath it turns grey when I add this code (in upload.php):

$dir_dest = "C:\xampp\htdocs\class uploads\desfolder\";

Edited by davy_yg


I tried this: $handle->Process('C:\xampp\htdocs\class uploads\desfolder\');

and still no file being copied to the destination folder and also the long script still appears after I press upload (Simple upload).

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.