Jump to content

Creating folders


jbonnett

Recommended Posts

Ok I have made a script that creates some folders and adds some files to them folders, the scrip successfully does this although I can write to the folder /var/www/users/"username"/photos/original/ but not any of the other folders in the photos e.g. /200x200/

 

any ideas?

<?php

/*
 * paths / names
 */
	$folderName = $_SESSION['reguname'];
	$uname = $session->username;
	$path = "users/";
	$files_path = "include/user_files/";
	$all_files = array("/photos","/photos/original","/photos/200x200","/photos/403x226","/photos/460x460","/photos/200x200","/photos/851x315","/files");
	$count = count($all_files);
	
for($i = 0; $i < $count; $i++){
/*
 * Complete paths
 */
	$register_dir = dirname(dirname(__FILE__)) . "/" . $path . $folderName;
	$register_dir_files = dirname(dirname(__FILE__)) . "/" . $path . $folderName . $all_files[$i];

	
	$session_dir = dirname(dirname(__FILE__)) . "/" . $path . $uname;
	$session_dir_files = dirname(dirname(__FILE__)) . "/" . $path . $uname . $all_files[$i];
	echo $session_dir_files;

	$normal_dir = $path . $folderName;	
	$normal_dir_files = $path . $folderName . $all_files[$i];
	
	$files_dir = dirname(dirname(__FILE__)) . "/" . $files_path;
	$files_dir_files = dirname(dirname(__FILE__)) . "/" . $files_path . $all_files[$i];

	
/*
 * Create the folder
 */
	//when register
		$create_register = mkdir($register_dir, 0777);
		$create_register_files = mkdir($register_dir_files, 0777);

		$chmod_register = chmod($register_dir, 0777);
		$chmod_register_files = chmod($register_dir_files, 0777);

	//when login
		$create_login = mkdir($session_dir, 0777);
		$create_login_files = mkdir($session_dir_files, 0777);

		$chmod_login = chmod($session_dir, 0777);
		$chmod_login_files = chmod($session_dir_files, 0777);

			
	if(!umask(0) & !$create_register & !umask(umask(0)) ||
	 !$chmod_register ||
	 !umask(0) &  !$create_login & !umask(umask(0)) ||
	 !$chmod_login ||
	 !umask(0) & !$create_register_files & !umask(umask(0)) ||
	 !$chmod_register_files ||
	 !umask(0) & !$create_login_files & !umask(umask(0)) ||
	 !$chmod_login_files) 
	{ 
	echo "Could not create your new folder contact the Administator.<br />"; 
	}

/*
 * Copying files to the folders "users/" and "users/username"
 */
	$cf = array("index.php", "file.php");
	foreach($cf as $af){
	// Users folder eg "users/username"
		$f = "$files_dir/$af"; 
		$nf = "$register_dir/$af";
 
		if (!copy($f, $nf)) { 
		echo "Error: could not copy \"$register_dir/$af\" to your user folder<br />";
		}

	// Users folder eg "users/"
		$f = "$files_dir/$af"; 
		$nf = "$session_dir/$af";
 
		if (!copy($f, $nf)) { 
		echo "Error: could not copy \"$session_dir/$af\" to the users folder<br />";
		}
	// Users folder eg "users/all"
		$f = "$files_dir/$af"; 
		$nf = "$create_register_files/$af";
 
		if (!copy($f, $nf)) { 
		echo "Error: could not copy \"$register_dir_files/$af\" to the users folder<br />";
		}
	// Users folder eg "users/all"
		$f = "$files_dir/$af"; 
		$nf = "$session_dir_files/$af";

		if (!copy($f, $nf)) { 
		echo "Error: could not copy \"$session_dir_files/$af\" to the users folder<br />";
		}	
	// Users folder eg "users/all"
		$f = "$files_dir/$af"; 
		$nf = "$session_dir_files/$af";

		if (!copy($f, $nf)) { 
		echo "Error: could not copy \"$session_dir_files/$af\" to the users folder<br />";
		}
	}
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.