PDA

View Full Version : help wrapping something up in a function..



Patch^
July 2nd, 2007, 03:36 AM
Hi all!

I've been experimenting with php, xml and as and some of it is quite new to me and I need a little help with a bit of code.

I've written a bit of code that creates folders and copy files. It works, but I want it only to work when I click submit from a form and I think to get it to work I have to either put it in a function or if statement.

PHP:



$mypath='slides/'.time();
$mypath2='slides/'.time().'/imgs';
$mypath3='slides/'.time().'/images';
$mypath4='slides/'.time().'/images/thumbs';

mkdir($mypath, 0777,true);
mkdir($mypath2, 0777, true);
mkdir($mypath3, 0777, true);
mkdir($mypath4, 0777, true);

//$user_name =$row_user['username']; ;

//chown($mypath, $user_name);


$file1 = 'templates/gallery.swf';
$file2 = 'templates/images.xml';
$file3 = 'templates/index.html';
$file4 = 'templates/AC_RunActiveContent.js';
$file5 = 'templates/imageForm+xml.php';
$file6 = 'templates/css.css';
//$file7 = 'templates/imgs';
$file8 = 'imgs/accept_icon.gif';
$file9 = 'imgs/error_icon.gif';
$file10 = 'imgs/img_icon.gif';
$file11 = 'imgs/warn_icon.gif';
$file12 = 'imgs/write_icon.gif';
$file13 = 'imgs/header2.gif';
$file14 = 'imgs/header.gif';

$newfile1 = $mypath.'/gallery.swf';
$newfile2 = $mypath.'/images.xml';
$newfile3 = $mypath.'/index.html';
$newfile4 = $mypath.'/AC_RunActiveContent.js';
$newfile5 = $mypath.'/imageForm+xml.php';
$newfile6 = $mypath.'/css.css';
//$newfile7 = $mypath.'/imgs';
$newfile8 = $mypath2.'/accept_icon.gif';
$newfile9 = $mypath2.'/error_icon.gif';
$newfile10 = $mypath2.'/img_icon.gif';
$newfile11 = $mypath2.'/warn_icon.gif';
$newfile12 = $mypath2.'/write_icon.gif';
$newfile13 = $mypath2.'/header2.gif';
$newfile14 = $mypath2.'/header.gif';

/*chmod($mypath, 777);

chmod($mypath.'/gallery.swf', 777);
chmod($mypath.'/images.xml', 777);
chmod($mypath.'/index.html', 777);
chmod($mypath.'/AC_RunActiveContent.js', 777);
chmod($mypath.'/imageForm+xml.php', 777);
chmod($mypath.'/css.css', 777);

chmod($mypath.'/imgs/accept_icon.gif', 777);
chmod($mypath.'/imgs/error_icon.gif', 777);
chmod($mypath.'/imgs/img_icon.gif', 777);
chmod($mypath.'/imgs/warn_icon.gif', 777);
chmod($mypath.'/imgs/write_icon.gif', 777);
chmod($mypath.'/imgs/header2.gif', 777);
chmod($mypath.'/imgs/header.gif', 777);

*/


if (!copy($file1, $newfile1))
{
echo "failed to copy $file1... \n";
}

if (!copy($file2, $newfile2))
{
echo "failed to copy $file2... \n";
}

if (!copy($file3, $newfile3))
{
echo "failed to copy $file3... \n";
}

if (!copy($file4, $newfile4))
{
echo "failed to copy $file4... \n";
}

if (!copy($file5, $newfile5))
{
echo "failed to copy $file5... \n";
}
if (!copy($file6, $newfile6))
{
echo "failed to copy $file6... \n";
}
/*if (!copy($file7, $newfile7))
{
echo "failed to copy $file7... \n";
}*/
if (!copy($file8, $newfile8))
{
echo "failed to copy $file7... \n";
}
if (!copy($file9, $newfile9))
{
echo "failed to copy $file10... \n";
}
if (!copy($file10, $newfile10))
{
echo "failed to copy $file10... \n";
}
if (!copy($file11, $newfile11))
{
echo "failed to copy $file11... \n";
}
if (!copy($file12, $newfile12))
{
echo "failed to copy $file12... \n";
}
if (!copy($file13, $newfile13))
{
echo "failed to copy $file13... \n";
}
if (!copy($file14, $newfile14))
{
echo "failed to copy $file14... \n";
}

//}
?>

HTML Form:



<form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="slideshowCreator">
<label>Name of Slide Show:</label><input name="name" type="text" value="" /><br /><div id="input_help">Make sure that this name is unique!"</div>
<label>Description of Slide Show:</label><textarea name="des" cols="26" rows="10" wrap="virtual"></textarea>
<br />
<input name="path" type="hidden" value="<? echo $mypath ?>" />
<input name="url2" type="hidden" value="<? echo $newfile5 ?>" />

<label></label><input name="Submit" type="submit" value="Submit">
<input type="hidden" name="MM_insert" value="slideshowCreator" />

</form>


I know it's probably something simple, but I just can't figure it out at the moment, i'm a little new to php to a certain degree...especially in mkdir and rmdir.

I will be very grateful if someone could help me with this :)

Charleh
July 2nd, 2007, 04:24 AM
You want to make the submit button take you to the same page but append something to the querystring/post vars (i.e. your editFormAction may append '?copyFiles=yes' on the end of the URL)

Then you just check the get/post vars (a bit rusty on PHP but I think it's $_POST["varName"] or something) and do an if test on it.

So if($_POST["copyFiles"] == "Yes") { // Do code }

Patch^
July 2nd, 2007, 04:32 AM
ah ok. thanks. I'll give it ago :D

Patch^
July 2nd, 2007, 04:42 AM
right I've sorta done what you said..but I'm not sure where to put "?copyFiles=yes" I just get a parse error..

php:


<?
if($_POST["copyFiles"] == "Yes"){

$mypath='slides/'.time();
$mypath2='slides/'.time().'/imgs';
$mypath3='slides/'.time().'/images';
$mypath4='slides/'.time().'/images/thumbs';

mkdir($mypath, 0777,true);
mkdir($mypath2, 0777, true);
mkdir($mypath3, 0777, true);
mkdir($mypath4, 0777, true);

//$user_name =$row_user['username']; ;

//chown($mypath, $user_name);


$file1 = 'templates/gallery.swf';
$file2 = 'templates/images.xml';
$file3 = 'templates/index.html';
$file4 = 'templates/AC_RunActiveContent.js';
$file5 = 'templates/imageForm+xml.php';
$file6 = 'templates/css.css';
//$file7 = 'templates/imgs';
$file8 = 'imgs/accept_icon.gif';
$file9 = 'imgs/error_icon.gif';
$file10 = 'imgs/img_icon.gif';
$file11 = 'imgs/warn_icon.gif';
$file12 = 'imgs/write_icon.gif';
$file13 = 'imgs/header2.gif';
$file14 = 'imgs/header.gif';

$newfile1 = $mypath.'/gallery.swf';
$newfile2 = $mypath.'/images.xml';
$newfile3 = $mypath.'/index.html';
$newfile4 = $mypath.'/AC_RunActiveContent.js';
$newfile5 = $mypath.'/imageForm+xml.php';
$newfile6 = $mypath.'/css.css';
//$newfile7 = $mypath.'/imgs';
$newfile8 = $mypath2.'/accept_icon.gif';
$newfile9 = $mypath2.'/error_icon.gif';
$newfile10 = $mypath2.'/img_icon.gif';
$newfile11 = $mypath2.'/warn_icon.gif';
$newfile12 = $mypath2.'/write_icon.gif';
$newfile13 = $mypath2.'/header2.gif';
$newfile14 = $mypath2.'/header.gif';

/*chmod($mypath, 777);

chmod($mypath.'/gallery.swf', 777);
chmod($mypath.'/images.xml', 777);
chmod($mypath.'/index.html', 777);
chmod($mypath.'/AC_RunActiveContent.js', 777);
chmod($mypath.'/imageForm+xml.php', 777);
chmod($mypath.'/css.css', 777);

chmod($mypath.'/imgs/accept_icon.gif', 777);
chmod($mypath.'/imgs/error_icon.gif', 777);
chmod($mypath.'/imgs/img_icon.gif', 777);
chmod($mypath.'/imgs/warn_icon.gif', 777);
chmod($mypath.'/imgs/write_icon.gif', 777);
chmod($mypath.'/imgs/header2.gif', 777);
chmod($mypath.'/imgs/header.gif', 777);

*/


if (!copy($file1, $newfile1))
{
echo "failed to copy $file1... \n";
}

if (!copy($file2, $newfile2))
{
echo "failed to copy $file2... \n";
}

if (!copy($file3, $newfile3))
{
echo "failed to copy $file3... \n";
}

if (!copy($file4, $newfile4))
{
echo "failed to copy $file4... \n";
}

if (!copy($file5, $newfile5))
{
echo "failed to copy $file5... \n";
}
if (!copy($file6, $newfile6))
{
echo "failed to copy $file6... \n";
}
/*if (!copy($file7, $newfile7))
{
echo "failed to copy $file7... \n";
}*/
if (!copy($file8, $newfile8))
{
echo "failed to copy $file7... \n";
}
if (!copy($file9, $newfile9))
{
echo "failed to copy $file10... \n";
}
if (!copy($file10, $newfile10))
{
echo "failed to copy $file10... \n";
}
if (!copy($file11, $newfile11))
{
echo "failed to copy $file11... \n";
}
if (!copy($file12, $newfile12))
{
echo "failed to copy $file12... \n";
}
if (!copy($file13, $newfile13))
{
echo "failed to copy $file13... \n";
}
if (!copy($file14, $newfile14))
{
echo "failed to copy $file14... \n";
}

}

?>


html:



<form action="<?php echo $editFormAction?copyFiles=yes; ?>" method="POST" enctype="multipart/form-data" name="slideshowCreator">
<label>Name of Slide Show:</label><input name="name" type="text" value="" /><br /><div id="input_help">Make sure that this name is unique!"</div>
<label>Description of Slide Show:</label><textarea name="des" cols="26" rows="10" wrap="virtual"></textarea>
<br />
<input name="path" type="hidden" value="<? echo $mypath ?>" />
<input name="url2" type="hidden" value="<? echo $newfile5 ?>" />

<label></label><input name="Submit" type="submit" value="Submit">
<input type="hidden" name="MM_insert" value="slideshowCreator" />

</form>

Parse Error:


Parse error: parse error, unexpected '=' in /var/www/vhosts/liamchapman.co.uk/httpdocs/cr/slideForm+xml.php on line 333

I know it's put in the wrong place, but I'm not sure where to put it exactly.

Any advice would be great, cheers.

Patch^
July 2nd, 2007, 05:12 AM
is it to do with the bit here?



$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

Charleh
July 2nd, 2007, 05:46 AM
is it to do with the bit here?



$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

Yeah well - I'm not sure where you've got that piece of code and I'm not sure if this is the best place to put it but you want to append to the end of that string

$editFormAction .= "&copyFiles=yes"

I'd hazard a guess at putting it inside the htmlentities function call

htmlentities($_SERVER['QUERY_STRING'] .= "&copyFiles=yes");

(oh it might be case sensitive too so just in case change your if statement to lower case 'yes' or test against 1 in the query string instead of the literal string 'yes')

Patch^
July 2nd, 2007, 05:56 AM
Thank you ever so much for helping me Charleh, but it's not working still :(

Here is an update on some of the code:

editFormAction:


$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING'] .= "&copyFiles=yes");

}

mkdir code etc:




if($_POST["copyFiles"] == "yes"){

$mypath='slides/'.time();
$mypath2='slides/'.time().'/imgs';
$mypath3='slides/'.time().'/images';
$mypath4='slides/'.time().'/images/thumbs';

mkdir($mypath, 0777,true);
mkdir($mypath2, 0777, true);
mkdir($mypath3, 0777, true);
mkdir($mypath4, 0777, true);

//$user_name =$row_user['username']; ;

//chown($mypath, $user_name);


$file1 = 'templates/gallery.swf';
$file2 = 'templates/images.xml';
$file3 = 'templates/index.html';
$file4 = 'templates/AC_RunActiveContent.js';
$file5 = 'templates/imageForm+xml.php';
$file6 = 'templates/css.css';
//$file7 = 'templates/imgs';
$file8 = 'imgs/accept_icon.gif';
$file9 = 'imgs/error_icon.gif';
$file10 = 'imgs/img_icon.gif';
$file11 = 'imgs/warn_icon.gif';
$file12 = 'imgs/write_icon.gif';
$file13 = 'imgs/header2.gif';
$file14 = 'imgs/header.gif';

$newfile1 = $mypath.'/gallery.swf';
$newfile2 = $mypath.'/images.xml';
$newfile3 = $mypath.'/index.html';
$newfile4 = $mypath.'/AC_RunActiveContent.js';
$newfile5 = $mypath.'/imageForm+xml.php';
$newfile6 = $mypath.'/css.css';
//$newfile7 = $mypath.'/imgs';
$newfile8 = $mypath2.'/accept_icon.gif';
$newfile9 = $mypath2.'/error_icon.gif';
$newfile10 = $mypath2.'/img_icon.gif';
$newfile11 = $mypath2.'/warn_icon.gif';
$newfile12 = $mypath2.'/write_icon.gif';
$newfile13 = $mypath2.'/header2.gif';
$newfile14 = $mypath2.'/header.gif';

/*chmod($mypath, 777);

chmod($mypath.'/gallery.swf', 777);
chmod($mypath.'/images.xml', 777);
chmod($mypath.'/index.html', 777);
chmod($mypath.'/AC_RunActiveContent.js', 777);
chmod($mypath.'/imageForm+xml.php', 777);
chmod($mypath.'/css.css', 777);

chmod($mypath.'/imgs/accept_icon.gif', 777);
chmod($mypath.'/imgs/error_icon.gif', 777);
chmod($mypath.'/imgs/img_icon.gif', 777);
chmod($mypath.'/imgs/warn_icon.gif', 777);
chmod($mypath.'/imgs/write_icon.gif', 777);
chmod($mypath.'/imgs/header2.gif', 777);
chmod($mypath.'/imgs/header.gif', 777);

*/


if (!copy($file1, $newfile1))
{
echo "failed to copy $file1... \n";
}

if (!copy($file2, $newfile2))
{
echo "failed to copy $file2... \n";
}

if (!copy($file3, $newfile3))
{
echo "failed to copy $file3... \n";
}

if (!copy($file4, $newfile4))
{
echo "failed to copy $file4... \n";
}

if (!copy($file5, $newfile5))
{
echo "failed to copy $file5... \n";
}
if (!copy($file6, $newfile6))
{
echo "failed to copy $file6... \n";
}
/*if (!copy($file7, $newfile7))
{
echo "failed to copy $file7... \n";
}*/
if (!copy($file8, $newfile8))
{
echo "failed to copy $file7... \n";
}
if (!copy($file9, $newfile9))
{
echo "failed to copy $file10... \n";
}
if (!copy($file10, $newfile10))
{
echo "failed to copy $file10... \n";
}
if (!copy($file11, $newfile11))
{
echo "failed to copy $file11... \n";
}
if (!copy($file12, $newfile12))
{
echo "failed to copy $file12... \n";
}
if (!copy($file13, $newfile13))
{
echo "failed to copy $file13... \n";
}
if (!copy($file14, $newfile14))
{
echo "failed to copy $file14... \n";
}

}

?>

And the form:


<form action="<?php echo $editFormAction; ?>" method="POST" enctype="multipart/form-data" name="slideshowCreator">
<label>Name of Slide Show:</label><input name="name" type="text" value="" /><br /><div id="input_help">Make sure that this name is unique!"</div>
<label>Description of Slide Show:</label><textarea name="des" cols="26" rows="10" wrap="virtual"></textarea>
<br />
<input name="path" type="hidden" value="<? echo $mypath ?>" />
<input name="url2" type="hidden" value="<? echo $newfile5 ?>" />

<label></label><input name="Submit" type="submit" value="Submit">
<input type="hidden" name="MM_insert" value="slideshowCreator" />

</form>

Thanks again!

Charleh
July 2nd, 2007, 06:35 AM
I'd try echoing the $editFormAction variable to the screen

just put

<?php echo $editFormAction; ?>

it at the top of your HTML page and see what it comes back with - what's happening now when you press the submit button?

Patch^
July 2nd, 2007, 06:47 AM
it did nothing :( I think it's because it goes to another page. I also edited the page so it came back to itself and still nothing.

But I check the database etc.. It seems to be putting in the 'title' and 'description', but it's not creating the directories and in the url and url2 parts in the database (this is where the url for the folders go) there is '<br />' or null.

cheers,

EDIT: I also put <?php echo $editFormAction; ?> on the page it goes to, still blank :(

Charleh
July 2nd, 2007, 06:52 AM
If the submit button is on the same page as the code that does the copying the query string needs to send you back to the same page but with something set to tell the code to run, it's known as a postback. If it's going to a different page when you click the submit button then your code on that page will never run.

Patch^
July 2nd, 2007, 06:54 AM
well the page that creates the folder is created in a directory and the location is sent to the database and on the page that it gets sent to is then read from the database. Like, it worked before, but it was creating a directory when I opened the page and it created another when I clicked submit.

EDIT: just had a quick idea, would it be easier/better if I had a form handler? Like open the form and then send to a redirect page where it creates the folder and then sends you to the page that displays it? etc?

I'd prefer it if it was all on one page though...

Charleh
July 2nd, 2007, 07:03 AM
Give it a try is all I can say, I'm not great with PHP!

simplistik
July 2nd, 2007, 08:17 AM
<?php
$submit = $_POST['Submit'];

if ( $submit )
{

$mypath='slides/'.time();
$mypath2='slides/'.time().'/imgs';
$mypath3='slides/'.time().'/images';
$mypath4='slides/'.time().'/images/thumbs';

mkdir($mypath, 0777,true);
mkdir($mypath2, 0777, true);
mkdir($mypath3, 0777, true);
mkdir($mypath4, 0777, true);

//$user_name =$row_user['username']; ;

//chown($mypath, $user_name);


$file1 = 'templates/gallery.swf';
$file2 = 'templates/images.xml';
$file3 = 'templates/index.html';
$file4 = 'templates/AC_RunActiveContent.js';
$file5 = 'templates/imageForm+xml.php';
$file6 = 'templates/css.css';
//$file7 = 'templates/imgs';
$file8 = 'imgs/accept_icon.gif';
$file9 = 'imgs/error_icon.gif';
$file10 = 'imgs/img_icon.gif';
$file11 = 'imgs/warn_icon.gif';
$file12 = 'imgs/write_icon.gif';
$file13 = 'imgs/header2.gif';
$file14 = 'imgs/header.gif';

$newfile1 = $mypath.'/gallery.swf';
$newfile2 = $mypath.'/images.xml';
$newfile3 = $mypath.'/index.html';
$newfile4 = $mypath.'/AC_RunActiveContent.js';
$newfile5 = $mypath.'/imageForm+xml.php';
$newfile6 = $mypath.'/css.css';
//$newfile7 = $mypath.'/imgs';
$newfile8 = $mypath2.'/accept_icon.gif';
$newfile9 = $mypath2.'/error_icon.gif';
$newfile10 = $mypath2.'/img_icon.gif';
$newfile11 = $mypath2.'/warn_icon.gif';
$newfile12 = $mypath2.'/write_icon.gif';
$newfile13 = $mypath2.'/header2.gif';
$newfile14 = $mypath2.'/header.gif';

/*chmod($mypath, 777);

chmod($mypath.'/gallery.swf', 777);
chmod($mypath.'/images.xml', 777);
chmod($mypath.'/index.html', 777);
chmod($mypath.'/AC_RunActiveContent.js', 777);
chmod($mypath.'/imageForm+xml.php', 777);
chmod($mypath.'/css.css', 777);

chmod($mypath.'/imgs/accept_icon.gif', 777);
chmod($mypath.'/imgs/error_icon.gif', 777);
chmod($mypath.'/imgs/img_icon.gif', 777);
chmod($mypath.'/imgs/warn_icon.gif', 777);
chmod($mypath.'/imgs/write_icon.gif', 777);
chmod($mypath.'/imgs/header2.gif', 777);
chmod($mypath.'/imgs/header.gif', 777);

*/


if (!copy($file1, $newfile1))
{
echo "failed to copy $file1... \n";
}

if (!copy($file2, $newfile2))
{
echo "failed to copy $file2... \n";
}

if (!copy($file3, $newfile3))
{
echo "failed to copy $file3... \n";
}

if (!copy($file4, $newfile4))
{
echo "failed to copy $file4... \n";
}

if (!copy($file5, $newfile5))
{
echo "failed to copy $file5... \n";
}
if (!copy($file6, $newfile6))
{
echo "failed to copy $file6... \n";
}
/*if (!copy($file7, $newfile7))
{
echo "failed to copy $file7... \n";
}*/
if (!copy($file8, $newfile8))
{
echo "failed to copy $file7... \n";
}
if (!copy($file9, $newfile9))
{
echo "failed to copy $file10... \n";
}
if (!copy($file10, $newfile10))
{
echo "failed to copy $file10... \n";
}
if (!copy($file11, $newfile11))
{
echo "failed to copy $file11... \n";
}
if (!copy($file12, $newfile12))
{
echo "failed to copy $file12... \n";
}
if (!copy($file13, $newfile13))
{
echo "failed to copy $file13... \n";
}
if (!copy($file14, $newfile14))
{
echo "failed to copy $file14... \n";
}
}
?>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data" name="slideshowCreator">
<fieldset>
<label>Name of Slide Show:</label><input name="name" type="text" value="" /><br /><div id="input_help">Make sure that this name is unique!"</div>
<label>Description of Slide Show:</label><textarea name="des" cols="26" rows="10" wrap="virtual"></textarea>
<br />
<input name="path" type="hidden" value="<? echo $mypath ?>" />
<input name="url2" type="hidden" value="<? echo $newfile5 ?>" />

<label></label><input name="Submit" type="submit" value="Submit" />
<input type="hidden" name="MM_insert" value="slideshowCreator" />
</fieldset>
</form>
</body>
</html>

Patch^
July 2nd, 2007, 11:11 AM
thanks simplistik, it almost works! It creates the folder when it submits, but it's not inserting
<? echo $mypath ?> and
<? echo $newfile5 ?> into the database. Any reason why this might happen?

cheers!!!!!!!!!! :D

simplistik
July 2nd, 2007, 11:21 AM
ummm as far as i can tell what you've posted has nothing to do with a database. it doesn't have any sort of database connectivity at all.

Patch^
July 2nd, 2007, 11:31 AM
ah ok then, I'll post the entire source for the page here then (obviously with private stuff removed):



<?php require_once('Connections/hidden.php'); ?>
<?php
//initialize the session
if (!isset($_SESSION)) {
  session_start();
}

// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
  $logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
  //to fully log out a visitor we need to clear the se ssion varialbles
  $_SESSION['MM_Username'] = NULL;
  $_SESSION['MM_UserGroup'] = NULL;
  $_SESSION['PrevUrl'] = NULL;
  unset($_SESSION['MM_Username']);
  unset($_SESSION['MM_UserGroup']);
  unset($_SESSION['PrevUrl']);
    
  $logoutGoTo = "log.php";
  if ($logoutGoTo) {
    header("Location: $logoutGoTo");
    exit;
  }
}
?>
<?php
if (!isset($_SESSION)) {
  session_start();
}
$MM_authorizedUsers = "hidden";
$MM_donotCheckaccess = "true";

// *** Restrict Access To Page: Grant or deny access  to this page
function isAuthorized($strUsers, $strGroups, $User Name, $UserGroup) { 
  // For security, start by assuming the visitor is NO T authorized. 
  $isValid = False; 

  // When a visitor has logged into this site, the Ses sion variable MM_Username set equal to their usern ame. 
  // Therefore, we know that a user is NOT logged in i f that Session variable is blank. 
  if (!empty($UserName)) { 
    // Besides being logged in, you may restrict access  to only certain users based on an ID established w hen they login. 
    // Parse the strings into arrays. 
    $arrUsers = Explode(",", $strUsers); 
    $arrGroups = Explode(",", $strGroups); 
    if (in_array($UserName, $arrUsers)) { 
      $isValid = true; 
    } 
    // Or, you may restrict access to only certain users  based on their username. 
    if (in_array($UserGroup, $arrGroups)) { 
      $isValid = true; 
    } 
    if (($strUsers == "") && true) { 
      $isValid = true; 
    } 
  } 
  return $isValid; 
}

$MM_restrictGoTo = "log_error.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {   
  $MM_qsChar = "?";
  $MM_referrer = $_SERVER['PHP_SELF'];
  if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
  if (isset($QUERY_STRING) && strlen($QUERY_STRING) > 0) 
  $MM_referrer .= "?" . $QUERY_STRING;
  $MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar  . "accesscheck=" . urlencode($MM_referrer);
  header("Location: ". $MM_restrictGoTo); 
  exit;
}
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $t heDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashe s($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_es cape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);

}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "slideshowCreator")) {
  $insertSQL = sprintf("INSERT INTO folder_url (name, des, url, url2) VALU ES (%s, %s, %s, %s)",
                       GetSQLValueString($_POST['name'], "text"),
                       GetSQLValueString($_POST['des'], "text"),
                       GetSQLValueString($_POST['path'], "text"),
                       GetSQLValueString($_POST['url2'], "text"));

  mysql_select_db($database_hidden, $hidden);
  $Result1 = mysql_query($insertSQL, $hidden) or d ie(mysql_error());

  $insertGoTo = "slides.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}

$colname_folder_url = "-1";
if (isset($_GET['id'])) {
  $colname_folder_url = $_GET['id'];
}
mysql_select_db($database_hidden, $hidden);
$query_folder_url = sprintf("SELECT * FROM folder_url WHERE id = %s", GetSQLValueString($colname_folder_url, "int"));
$folder_url = mysql_query($query_folder_url, $hidd en) or die(mysql_error());
$row_folder_url = mysql_fetch_assoc($folder_url);
$totalRows_folder_url = mysql_num_rows($folder_url );

mysql_select_db($database_hidden, $hidden);
$query_user = "SELECT * FROM users";
$user = mysql_query($query_user, $hidden) or die(m ysql_error());
$row_user = mysql_fetch_assoc($user);
$totalRows_user = mysql_num_rows($user);
?><!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>campbell &amp; Rowley Slide Show Creator Prototype.</title>
<link href="css.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="centre_site">
<div id="site_header2"></div>

<?php 

$name=$_POST['name'];
$des=$_POST['des'];
$url=$_POST['url'];

?>

<?php

/*function dircopy($srcdir, $dstdir, $verbose = fal se) {
  $num = 0;
  if(!is_dir($dstdir)) mkdir($dstdir);
  if($curdir = opendir($srcdir)) {
    while($file = readdir($curdir)) {
      if($file != '.' && $file != '..') {
        $srcfile = $srcdir . 'imgs' . $file;
        $dstfile = $dstdir . 'slides/'time(); . $file;
        if(is_file($srcfile)) {
          if(is_file($dstfile)) $ow = filemtime($s rcfile) - filemtime($dstfile); else $ow = 1;
          if($ow > 0) {
            if($verbose) echo "Copying '$srcfile' to '$dstfile'...";
            if(copy($srcfile, $dstfile)) {
              touch($dstfile, filemtime($srcfile)) ; $num++;
              if($verbose) echo "OK\n";
            }
            else echo "Error: File '$srcfile' could not be copied!\n";
          }                   
        }
        else if(is_dir($srcfile)) {
          $num += dircopy($srcfile, $dstfile, $ver bose);
        }
      }
    }
    closedir($curdir);
  }
  return $num;
}*/

/////not too sure about this bit here, how to get it to  create a directory when I click submit etc../////

//if (slideshowCreator !=""){

//if($_POST["copyFiles"] == "yes"){

//if($_POST['name'] && $_POST['des'] == true){

//if($_SERVER['QUERY_STRING'] == true){

$submit = $_POST['Submit'];

    if ( $submit ) 
    {
    
        $mypath='slides/'.time();
        $mypath2='slides/'.time().'/imgs';
        $mypath3='slides/'.time().'/images';
        $mypath4='slides/'.time().'/images/thumbs';
        
        mkdir($mypath, 0777,true);
        mkdir($mypath2, 0777, true);
        mkdir($mypath3, 0777, true);
        mkdir($mypath4, 0777, true);
        
        //$user_name =$row_user['username']; ;
        
        //chown($mypath, $user_name);
        
        
        $file1 = 'templates/gallery.swf';
        $file2 = 'templates/images.xml';
        $file3 = 'templates/index.html';
        $file4 = 'templates/AC_RunActiveContent.js';
        $file5 = 'templates/imageForm+xml.php';
        $file6 = 'templates/css.css';
        //$file7 = 'templates/imgs';
        $file8 = 'imgs/accept_icon.gif';
        $file9 = 'imgs/error_icon.gif';
        $file10 = 'imgs/img_icon.gif';
        $file11 = 'imgs/warn_icon.gif';
        $file12 = 'imgs/write_icon.gif';
        $file13 = 'imgs/header2.gif';
        $file14 = 'imgs/header.gif';
        
        $newfile1 = $mypath.'/gallery.swf';
        $newfile2 = $mypath.'/images.xml';
        $newfile3 = $mypath.'/index.html';
        $newfile4 = $mypath.'/AC_RunActiveContent.js';
        $newfile5 = $mypath.'/imageForm+xml.php';
        $newfile6 = $mypath.'/css.css';
        //$newfile7 = $mypath.'/imgs';
        $newfile8 = $mypath2.'/accept_icon.gif';
        $newfile9 = $mypath2.'/error_icon.gif';
        $newfile10 = $mypath2.'/img_icon.gif';
        $newfile11 = $mypath2.'/warn_icon.gif';
        $newfile12 = $mypath2.'/write_icon.gif';
        $newfile13 = $mypath2.'/header2.gif';
        $newfile14 = $mypath2.'/header.gif';
        
        /*chmod($mypath, 777);
        
        chmod($mypath.'/gallery.swf', 777);
        chmod($mypath.'/images.xml', 777);
        chmod($mypath.'/index.html', 777);
        chmod($mypath.'/AC_RunActiveContent.js', 777);
        chmod($mypath.'/imageForm+xml.php', 777);
        chmod($mypath.'/css.css', 777);
        
        chmod($mypath.'/imgs/accept_icon.gif', 777);
        chmod($mypath.'/imgs/error_icon.gif', 777);
        chmod($mypath.'/imgs/img_icon.gif', 777);
        chmod($mypath.'/imgs/warn_icon.gif', 777);
        chmod($mypath.'/imgs/write_icon.gif', 777);
        chmod($mypath.'/imgs/header2.gif', 777);
        chmod($mypath.'/imgs/header.gif', 777);
        
        */
        
        
        if (!copy($file1, $newfile1))
        {
            echo "failed to copy $file1... \n";
        }
        
        if (!copy($file2, $newfile2))
        {
            echo "failed to copy $file2... \n";
        }
        
        if (!copy($file3, $newfile3))
        {
            echo "failed to copy $file3... \n";
        }
        
        if (!copy($file4, $newfile4))
        {
            echo "failed to copy $file4... \n";
        }
        
        if (!copy($file5, $newfile5))
        {
            echo "failed to copy $file5... \n";
        }
        if (!copy($file6, $newfile6))
        {
            echo "failed to copy $file6... \n";
        }
        /*if (!copy($file7, $newfile7))
        {
            echo "failed to copy $file7... \n";
        }*/
        if (!copy($file8, $newfile8))
        {
            echo "failed to copy $file7... \n";
        }
        if (!copy($file9, $newfile9))
        {
            echo "failed to copy $file10... \n";
        }
        if (!copy($file10, $newfile10))
        {
            echo "failed to copy $file10... \n";
        }
        if (!copy($file11, $newfile11))
        {
            echo "failed to copy $file11... \n";
        }
        if (!copy($file12, $newfile12))
        {
            echo "failed to copy $file12... \n";
        }
        if (!copy($file13, $newfile13))
        {
            echo "failed to copy $file13... \n";
        }
        if (!copy($file14, $newfile14))
        {
            echo "failed to copy $file14... \n";
        }
    }
?>

<p align="left"><a href="slides.php">View current Slideshows</a></p><p align="right"><a href="<?php echo $logoutAction ?>">Log out</a></p>

<div id="form_centre">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data" name="slideshowCreator">
            <label>Name of Slide Show:</label><input name="name" type="text" value="" /><br /><div id="input_help">Make sure that this name is unique!"</div>
            <label>Description of Slide Show:</label><textarea name="des" cols="26" rows="10" wrap="virtual"></textarea>
            <br />
            <input name="path" type="hidden" value="<? echo $mypath ?>" />
            <input name="url2" type="hidden" value="<? echo $newfile5 ?>" />
            
            <label></label><input name="Submit" type="submit" value="Submit" />
            <input type="hidden" name="MM_insert" value="slideshowCreator" />
    </form>
<br />

</div><br />
<div id="copyright" align="center">hidden</div>
</div>

</body>
</html>
<?php
mysql_free_result($folder_url);

mysql_free_result($user);
?>



I think thats it :)

simplistik
July 3rd, 2007, 08:14 AM
well... honestly i haven't got the slightest idea where to start in that script. looks like a pre-made one or somethin and i'm having a hard time weeding through it. :*( sorry

Patch^
July 3rd, 2007, 08:16 AM
ah ok, no worries. I used dreamweaver. thanks for taking a look though :D

Patch^
July 3rd, 2007, 10:31 AM
Anyone else wanna have ago at helping me out? lol...please!!?

Patch^
July 4th, 2007, 05:08 PM
quick bump? Still haven't worked it out :(