Pure PHP Upload 2 Support Product Page

Creating variable upload folder

Asked 12 Oct 2010 10:16:48
1
has this question
12 Oct 2010 10:16:48 Phil Boyle posted:
Hi
I am trying to upload to different folders generated in pure php upload2 using a session variable
On first pages sessiontest1.php I have this code:

<?php
session_start();
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php

 echo "This is a test of the sessions feature.
 <form action='sessionTest2.php' method='POST'>
 <input type='hidden' name='form_var' value ='xxxxxxxxxxs'>
 <input type='submit' value='go to next page' >
 </form> ";
  ?>
</body>
</html>


And on second page sessionTest2.php I have this


<?php require_once('../ScriptLibrary/incPureUpload.php'); ?>
<?php
session_start();
?>



<?php
// Pure PHP Upload 2.1.10
$ppu = new pureFileUpload();
$ppu->path = "galleries/".$_POST['form_var'];
$ppu->extensions = "";
$ppu->formName = "form1";
$ppu->storeType = "file";
$ppu->sizeLimit = "";
$ppu->nameConflict = "over";
$ppu->requireUpload = "true";
$ppu->minWidth = "";
$ppu->minHeight = "";
$ppu->maxWidth = "";
$ppu->maxHeight = "";
$ppu->saveWidth = "";
$ppu->saveHeight = "";
$ppu->timeout = "600";
$ppu->progressBar = "";
$ppu->progressWidth = "300";
$ppu->progressHeight = "100";
$ppu->redirectURL = "";
$ppu->checkVersion("2.1.10");
$ppu->doUpload();

if (isset($editFormAction)) {
  if (isset($_SERVER['QUERY_STRING'])) {
      if (!eregi("GP_upload=true", $_SERVER['QUERY_STRING'])) {
        $editFormAction .= "&GP_upload=true";
        }
  } else {
    $editFormAction .= "?GP_upload=true";
  }
}


?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language='javascript' src='../ScriptLibrary/incPureUpload.js'></script>
</head>

<body>

<form action="<?php echo $GP_uploadAction; ?>" method="post"   enctype="multipart/form-data"  name="form1"  id="form1" onSubmit="checkFileUpload(this,'',true,'','','','','','','');return document.MM_returnValue" >
  
 

  
  
  <fieldset><legend>Use this to upload a photo for everything</legend>
   <p>
      <label  ><strong>Photo</strong></label><br/>
      <input name="pImage"   type="file" class="field" onChange="checkOneFileUpload(this,'',true,'','','','','','','')"    />
  </p>
  </fieldset>
 <div id="buttons">
  
  
  <input type="submit" value="submit">
  &nbsp;&nbsp;
  <input type="reset" value="reset">
</form>
</body>
</html>


This creates the directory xxxxxxxxxxs but doesn't upload the image to it.

But if I have this on sessionTest1.php:

<?php
session_start();
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
$_SESSION['session_var'] = "testing2";
 echo "This is a test of the sessions feature.
 <form action='sessionTest2.php' method='POST'>
 <input type='hidden' name='form_var' value ='xxxxxxxxxxs'>
 <input type='submit' value='go to next page' >
 </form> ";
  ?>
</body>
</html>



And this on sessionTest2.php

<?php require_once('../ScriptLibrary/incPureUpload.php'); ?>
<?php
session_start();
?>



<?php
// Pure PHP Upload 2.1.10
$ppu = new pureFileUpload();
$ppu->path = "galleries/".$_SESSION['session_var'];
$ppu->extensions = "";
$ppu->formName = "form1";
$ppu->storeType = "file";
$ppu->sizeLimit = "";
$ppu->nameConflict = "over";
$ppu->requireUpload = "true";
$ppu->minWidth = "";
$ppu->minHeight = "";
$ppu->maxWidth = "";
$ppu->maxHeight = "";
$ppu->saveWidth = "";
$ppu->saveHeight = "";
$ppu->timeout = "600";
$ppu->progressBar = "";
$ppu->progressWidth = "300";
$ppu->progressHeight = "100";
$ppu->redirectURL = "";
$ppu->checkVersion("2.1.10");
$ppu->doUpload();

if (isset($editFormAction)) {
  if (isset($_SERVER['QUERY_STRING'])) {
      if (!eregi("GP_upload=true", $_SERVER['QUERY_STRING'])) {
        $editFormAction .= "&GP_upload=true";
        }
  } else {
    $editFormAction .= "?GP_upload=true";
  }
}


?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language='javascript' src='../ScriptLibrary/incPureUpload.js'></script>
</head>

<body>

<form action="<?php echo $GP_uploadAction; ?>" method="post"   enctype="multipart/form-data"  name="form1"  id="form1" onSubmit="checkFileUpload(this,'',true,'','','','','','','');return document.MM_returnValue" >
  
 

  
  
  <fieldset><legend>Use this to upload a photo for everything</legend>
   <p>
      <label  ><strong>Photo</strong></label><br/>
      <input name="pImage"   type="file" class="field" onChange="checkOneFileUpload(this,'',true,'','','','','','','')"    />
  </p>
  </fieldset>
 <div id="buttons">
  
  
  <input type="submit" value="submit">
  &nbsp;&nbsp;
  <input type="reset" value="reset">
</form>
</body>
</html>


It works, creates the directory and uploads the image

So how can I get it to work How do I make this "testing2" bit dynamic Or how do I get form_var to create the directory and upload the file?

<?php $_SESSION['session_var'] = "testing2";
 echo "This is a test of the sessions feature.
 <form action='sessionTest2.php' method='POST'>
 <input type='hidden' name='form_var' value ='xxxxxxxxxxs'>
 <input type='submit' value='go to next page' >
 </form> ";
  ?>

Thanks
Phil

Replies

Replied 14 Oct 2010 10:31:26
14 Oct 2010 10:31:26 Miroslav Zografski replied:
Hello Phil,

Try messing the both examples.
Use first page from first example to post the form and on second page define your session variable BEFORE ppu code and assign to it the post from the form. Then use the session variable inside the PPU code.

Regards,
Replied 18 Oct 2010 23:24:39
18 Oct 2010 23:24:39 Phil Boyle replied:
Thanks I'll give it a try.
Replied 21 Oct 2010 09:48:56
21 Oct 2010 09:48:56 Phil Boyle replied:
I tried to define the session variable

'on second page define your session variable BEFORE ppu code and assign to it the post from the form. Then use the session variable inside the PPU code. '
But unfortunately I couldn't do it:
Here is what I had on page1:

<?php
session_start();
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php

 echo "This is a test of the sessions feature.
 <form action='sessionTest2.php' method='POST'>
 <input type='hidden' name='form_var' value ='xxxxxxxxx'>
 <input type='submit' value='go to next page' >
 </form> ";
  ?>
</body>
</html>


Here is what I put on page2 to try and define the session variable:

<?php require_once('../ScriptLibrary/incPureUpload.php'); ?>
<?php
session_start();
session_register ("form_var");	
$HTTP_SESSION_VARS ["form_var"] = $form_var;	

?>



<?php
// Pure PHP Upload 2.1.10
$ppu = new pureFileUpload();
$ppu->path = "galleries/".$_SESSION['form_var'];
$ppu->extensions = "";
$ppu->formName = "form1";
$ppu->storeType = "file";
$ppu->sizeLimit = "";
$ppu->nameConflict = "over";
$ppu->requireUpload = "true";
$ppu->minWidth = "";
$ppu->minHeight = "";
$ppu->maxWidth = "";
$ppu->maxHeight = "";
$ppu->saveWidth = "";
$ppu->saveHeight = "";
$ppu->timeout = "600";
$ppu->progressBar = "";
$ppu->progressWidth = "300";
$ppu->progressHeight = "100";
$ppu->redirectURL = "";
$ppu->checkVersion("2.1.10");
$ppu->doUpload();

if (isset($editFormAction)) {
  if (isset($_SERVER['QUERY_STRING'])) {
	  if (!eregi("GP_upload=true", $_SERVER['QUERY_STRING'])) {
  	  $editFormAction .= "&GP_upload=true";
		}
  } else {
    $editFormAction .= "?GP_upload=true";
  }
}


?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language='javascript' src='../ScriptLibrary/incPureUpload.js'></script>
</head>

<body>

<form action="<?php echo $GP_uploadAction; ?>" method="post"   enctype="multipart/form-data"  name="form1"  id="form1" onSubmit="checkFileUpload(this,'',true,'','','','','','','');return document.MM_returnValue" >
  
 

  
  
  <fieldset><legend>Use this to upload a photo for everything</legend>
   <p>
      <label  ><strong>Photo</strong></label><br/>
      <input name="pImage"   type="file" class="field" onChange="checkOneFileUpload(this,'',true,'','','','','','','')"    />
  </p>
  </fieldset>
 <div id="buttons">
  
  
  <input type="submit" value="submit">
  &nbsp;&nbsp;
  <input type="reset" value="reset">
</form>
</body>
</html>



This version didn't even create the folder and I got the error message:
Notice: Undefined variable: form_var in C:\HostingSpaces\RW\rochellewithell.co.nz\wwwroot\cms\sessionTest2.php on line 5

Hope you can point me in the right direction
Thanks
Phil
Replied 25 Oct 2010 10:27:45
25 Oct 2010 10:27:45 Miroslav Zografski replied:
Hello Phil,

Use :

$_SESSION["form_var"] = $_POST["form_var"]; 


instead of :

$HTTP_SESSION_VARS ["form_var"] = $form_var;


Regards,
Replied 29 Oct 2010 03:14:57
29 Oct 2010 03:14:57 Phil Boyle replied:
Thanks your help is appreciated. I'll give that a try.
Replied 29 Oct 2010 03:44:53
29 Oct 2010 03:44:53 Phil Boyle replied:
No it is creating the folder but the image is not going inside. I am getting the error message

Notice: Undefined index: form_var in C:\HostingSpaces\RW\rochellewithell.co.nz\wwwroot\cms\sessionTest2.php on line 5
Replied 29 Oct 2010 10:06:28
29 Oct 2010 10:06:28 Miroslav Zografski replied:
Hello Phil,

could you please post again the code of the second page - sessionTest2.php I think it was?

Regards,
Replied 01 Nov 2010 02:23:18
01 Nov 2010 02:23:18 Phil Boyle replied:
The code from sessionTest2.php:
<?php require_once('../ScriptLibrary/incPureUpload.php'); ?>
<?php
session_start();
session_register ("form_var";
$_SESSION["form_var"] = $_POST["form_var"];
?>



<?php
// Pure PHP Upload 2.1.10
$ppu = new pureFileUpload();
$ppu->path = "galleries/".$_SESSION['form_var'];
$ppu->extensions = "";
$ppu->formName = "form1";
$ppu->storeType = "file";
$ppu->sizeLimit = "";
$ppu->nameConflict = "over";
$ppu->requireUpload = "true";
$ppu->minWidth = "";
$ppu->minHeight = "";
$ppu->maxWidth = "";
$ppu->maxHeight = "";
$ppu->saveWidth = "";
$ppu->saveHeight = "";
$ppu->timeout = "600";
$ppu->progressBar = "";
$ppu->progressWidth = "300";
$ppu->progressHeight = "100";
$ppu->redirectURL = "";
$ppu->checkVersion("2.1.10";
$ppu->doUpload();

if (isset($editFormAction)) {
if (isset($_SERVER['QUERY_STRING'])) {
if (!eregi("GP_upload=true", $_SERVER['QUERY_STRING'])) {
$editFormAction .= "&GP_upload=true";
}
} else {
$editFormAction .= "?GP_upload=true";
}
}


?>
<html xmlns="www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language='javascript' src='../ScriptLibrary/incPureUpload.js'></script>
</head>

<body>

<form action="<?php echo $GP_uploadAction; ?>" method="post" enctype="multipart/form-data" name="form1" id="form1" onSubmit="checkFileUpload(this,'',true,'','','','','','','');return document.MM_returnValue" >





<fieldset><legend>Use this to upload a photo for everything</legend>
<p>
<label ><strong>Photo</strong></label><br/>
<input name="pImage" type="file" class="field" onChange="checkOneFileUpload(this,'',true,'','','','','','','')" />
</p>
</fieldset>
<div id="buttons">


<input type="submit" value="submit">
&nbsp;&nbsp;
<input type="reset" value="reset">
</form>
</body>
</html>

Thanks
Phil
Replied 30 Nov 2010 00:36:04
30 Nov 2010 00:36:04 Phil Boyle replied:
Hi
Just wondering if I've been forgotten?
Replied 30 Nov 2010 09:52:33
30 Nov 2010 09:52:33 Miroslav Zografski replied:
Hello Phil,

I'm sorry for the delay.
So you can have that folder passed but you need to add a bit of a check because otherwise the variable will be overwritten, like follows...
page1 :
<?php
session_start();
?>
<!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>Untitled Document</title>  
</head>
<body>
<?php

 echo "This is a test of the sessions feature."?>
 <form action='testFolderCreation.php' method='POST'>
 <input type='hidden' name='form_var' id="form_var" value ='xxxxxxxxx'>
 <input type='submit' value='go to next page' >
 </form>
</body>
</html>


page 2:
<?php require_once('ScriptLibrary/incPureUpload.php'); ?>
<?php
session_start();
?>
<?php 
//Here we check if the POST is new and if it is we assign the new value to the session var
if (isset($_POST['form_var']) && ($_POST['form_var'] != "")){
	$alabala = $_POST['form_var'];
	$_SESSION['alabala'] = $alabala; 
}	
?>
<?php
// Pure PHP Upload 2.1.10
$ppu = new pureFileUpload();
$ppu->path = "testCreateFolder/" . $_SESSION['alabala'];
$ppu->extensions = "GIF,JPG,JPEG,BMP,PNG";
$ppu->formName = "form1";
$ppu->storeType = "file";
$ppu->sizeLimit = "";
$ppu->nameConflict = "over";
$ppu->requireUpload = "true";
$ppu->minWidth = "";
$ppu->minHeight = "";
$ppu->maxWidth = "";
$ppu->maxHeight = "";
$ppu->saveWidth = "";
$ppu->saveHeight = "";
$ppu->timeout = "600";
$ppu->progressBar = "coolGreenFlashProgress.htm";
$ppu->progressWidth = "300";
$ppu->progressHeight = "100";
$ppu->redirectURL = "";
$ppu->checkVersion("2.1.10");
$ppu->doUpload();

if (isset($editFormAction)) {
  if (isset($_SERVER['QUERY_STRING'])) {
	  if (!eregi("GP_upload=true", $_SERVER['QUERY_STRING'])) {
  	  $editFormAction .= "&GP_upload=true";
		}
  } else {
    $editFormAction .= "?GP_upload=true";
  }
}
?>
<!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>Untitled Document</title>
<script language='JavaScript' src='ScriptLibrary/incPureUpload.js' type="text/javascript"></script>
</head>

<body>
this is only a test echoFolder = <?php echo $_SESSION['alabala'];?><br/>
<form action="<?php echo $GP_uploadAction; ?>" method="post" enctype="multipart/form-data" name="form1" id="form1" onsubmit="checkFileUpload(this,'GIF,JPG,JPEG,BMP,PNG',true,'','','','','','','');showProgressWindow('coolGreenFlashProgress.htm',300,100);return document.MM_returnValue">
  <p>
    <label for="file">File</label>
    <input name="file" type="file" id="file" onchange="checkOneFileUpload(this,'GIF,JPG,JPEG,BMP,PNG',true,'','','','','','','')" />
  </p>
  <p>
    <input type="submit" name="sub" id="sub" value="Submit" />
  </p>
</form>
</body>
</html>


Once again excuse my delay.

Regards,
Replied 30 Nov 2010 23:07:33
30 Nov 2010 23:07:33 Phil Boyle replied:
No worries Miroslav. I really appreciate your help.
Replied 02 Dec 2010 08:26:25
02 Dec 2010 08:26:25 Phil Boyle replied:
That's it. Fantastic!!!

Reply to this topic