I have no finished it completely, but the last things are lined out. I keep getting errors in CMD. What I am aiming to do is to create a code that will give my company the ability to upload images into a site builder, but we want them to be categorized. Just give me a few pointers this is my first code so don't be too brutal.

<?php
	# import libs
	include("lib/image.lib.php");

# config
define("IMPORT_DIR", "source/import/");
define("OUTPUT_ORIGINAL", "source/original/");
define("OUTPUT_THUMBNAIL", "source/thumbnail/");

# ---------------------------------------------------------------------------

# Next Steps:
# - Don't reprocess existing images
#   - 1) Read the database
#   - 2) Compare with existing content
#   - 3) Only process new found images








# load import dir
$d = dir(IMPORT_DIR);

# initial db
/*$db = Array("current"=>0, "rows"=>Array());

{
	current: 0,
	rows: [
		{categorie: '', items: [
			{id: '', name: '', ...},
		]},
		{categorie: '', items: [
			{id: '', name: '',
		]},
		{categorie: '', items: [

		]},


	]

}*/

# cycle
$current = 1;
while (false !== ($entry = $d->read())) {
	if($entry!="."&&$entry!="..") {
		// get categorie name
		$categoriename = strtolower($entry);
		// initialize items
		$items = Array();
		// create directory name
		$dn = sprintf("%s%s/", IMPORT_DIR, $entry);
		// load directory
		$fd = dir($dn);
		// cycle
		while (false !== ($fl = $fd->read())) {
			if($fl!="."&&$fl!=".."&&!is_dir(sprintf("%s%s", $dn, $fl))) {
				// create main image
				$ofn = sprintf("%s%s-%s", OUTPUT_ORIGINAL, $current, $fl);
				$img = new mgImage(sprintf("%s%s", $dn, $fl));
				if($img->Width()>1920) {
					$img->ResizeWidth(1920);
				}
				$img->asJPG($ofn, 85);

				// create thumbnail
				$tfn = sprintf("%s%s-%s", OUTPUT_THUMBNAIL, $current, $fl);
				$img = new mgImage(sprintf("%s%s", $dn, $fl));
				$img->ResizeWidth(250);
				$img->asJPG($tfn, 50); 


				// add to items
				$items[] = Array(
					"id"=>sprintf("%s-%s", $current, strtolower($fl)),
					"premium"=>strpos($fl, "premium")!==false?1:0,
					"name"=>strtolower($fl),
					"original"=>sprintf("/%s", strtolower($ofn)),
					"thumbnail"=>sprintf("/%s", strtolower($tfn))
				);
			}
		}

		// assign database
		$db["rows"][] = Array("categorie"=>$categoriename, "items"=>$items);
		// update current
		$current += 1;
	}
}

$db["current"] = $current;

# finish
$d->close();

# write db
file_put_contents("database.json", json_encode($db));
/*$db = ''
$d = ''
$result = array_merge($'db', $'');*/
?>
    Write a Reply...