POST data in een var

To writr a directory, wich can be different, I would to like to use $_POST[data] in a var.
The script is uploading an image each time in a different directory send by $_POST[data]
This is not working:
var $originalDir = ‘…/…/data/original/$_POST[cat]’;

any solutions?

regards Koosje

I’m a noob, but I think it should be:
[php]
var $originalDir = “…/…/data/original/$_POST[‘cat’]”;
[/php]
Note the double quotes around the entire string, and the single quotes around cat.
Give it shot, at worst it still won’t work.

It’s not working as soon double quotes or second $ is present

hello Koosje,
use this
[php]

<? var $originalDir = "../../data/original/".$_POST['cat']; ?>

SR
[/php]

It seems it doesn’t work, here by the whole script, maybe someone sees if it is possible or not or a fairytail:

[php]<?php
$myImageUpload = new maxImageUpload();
//$myUpload->setUploadLocation(getcwd().DIRECTORY_SEPARATOR);
$myImageUpload->uploadImage();
?>

<?php class maxImageUpload { // Maximum upload size var $maxUploadSize = 10; // 10 Mb // Image sizes var $normalWidth = 320; var $normalHeight = 200; var $thumbWidth = 150; var $thumbHeight = 94; // Image quality var $imageQualityNormal = 5; //1:Poor ... 5:Very good var $imageQualityThumb = 5; //1:Poor ... 5:Very good // Directories to store images var $baseDir = ''; // var $originalDir = "../../data/original/".$_POST['cat'];//this has to work but it doesn't var $originalDir = '../../data/original'; var $normalDir = '../../data/normal'; var $thumbDir = '../../data/thumbnail'; // File postfixes var $originalPrefix = ''; var $normalPrefix = ''; var $thumbPrefix = ''; // Internal used variables var $error = ''; var $maxMemoryUsage = 128; // 128 Mb /** * Constructor to initialize class varaibles * The upload locations will be set to the actual * working directory * * @return maxImageUpload */ function maxImageUpload(){ if (!file_exists($this->baseDir)) { if (!@mkdir($this->baseDir)){ $this->baseDir = getcwd(); } } $this->originalDir = $this->baseDir.DIRECTORY_SEPARATOR.$this->originalDir.DIRECTORY_SEPARATOR; if (!file_exists($this->originalDir)) { mkdir($this->originalDir); } $this->normalDir = $this->baseDir.DIRECTORY_SEPARATOR.$this->normalDir.DIRECTORY_SEPARATOR; if (!file_exists($this->normalDir)) { mkdir($this->normalDir); } $this->thumbDir = $this->baseDir.DIRECTORY_SEPARATOR.$this->thumbDir.DIRECTORY_SEPARATOR; if (!file_exists($this->thumbDir)) { mkdir($this->thumbDir); } } /** * This function sets the directory where to upload the file * In case of Windows server use the form: c:\\temp * In case of Unix server use the form: /tmp * * @param String Directory where to store the files */ function setUploadBaseLocation($dir){ $this->baseDir = $dir; } function showUploadForm($msg='',$error=''){ ?>
  1. <?=$arrcat?>
<?php if ($msg != ''){ echo '

'.$msg.'

'; } else if ($error != ''){ echo '

'.$error.'

'; } ?>
<?php }
function uploadImage(){
    $result = true;
    
    if (!isset($_POST['submitBtn'])){
        $this->showUploadForm();
    } else {
        $msg = '';
        $error = '';
        
        //Check image type. Only jpeg images are allowed
        if ( (($_FILES['myfile']['type'])=='image/pjpeg') || (($_FILES['myfile']['type'])=='image/jpeg')) {
           
           // Check the output directories
           if ($this->checkDirs()){
               $target_path = $this->originalDir . basename( $_FILES['myfile']['name']);

               if(@move_uploaded_file($_FILES['myfile']['tmp_name'], $target_path)) {
                  $msg = basename( $_FILES['myfile']['name']).  
               " (".filesize($target_path)." bytes)";
               } else{
                  $error = "The upload process failed!";
                  $result = false;
               }

               // Store resized images
               if ($result){
                  $this->setMemoryLimit($target_path);

                  // Create normal size image
                  $dest = $this->normalDir.$this->normalPrefix.basename($_FILES['myfile']['name']);
                  $this->resizeImage($target_path,$dest,$this->normalWidth,$this->normalHeight,$this->imageQualityNormal);
                  //$msg .= "<br>".basename($dest)." (".filesize($dest)." bytes) was stored!";

                  // Create thumbnail image
                  $dest = $this->thumbDir.$this->thumbPrefix.basename($_FILES['myfile']['name']);
                  $this->resizeImage($target_path,$dest,$this->thumbWidth,$this->thumbHeight,$this->imageQualityThumb);
                  //$msg .= "<br/>".basename($dest)." (".filesize($dest)." bytes) was stored!";

?>[/php]

Het zal aan mijn ongedurigheid liggen maar het gaat niet lukken, zelfs niet om een stuk teskt in te voegen,
var $originalDir = ‘…/…/data/original/’ . “27”;
etc etc. 27 is een bestaande directory waarin een foto geplaatst moet worden.

Hoi, what appears to be the problem?
$originalDir = ‘…/…/data/original/’ . “27”; should work. ( It should make $originalDir == ‘…/…/data/original/27’ ) If it doesn’t then it’s PHP that isn’t working properly. But just to make sure, what happens if before the line where you append (.) $_POST[‘cat’] you first echo it? Do you see the expected value on your screen?
Ah! I see, no, in that location it will not set. It will only accept simple assignments there.
What you can do is write an init() function that you call from the creator.
inside a class {} you can only do simple assignments, it’s not even possible to do “public $time = time();”.

Hope I put it in somewhat understandable language.

BTW, didn’t the script show errors? I think it should have.

( If not, try this one ini_set('display_errors', 'On'); )

Shure I’ve echo it and it shows the value of POST-data, even when I’ve put it in an another $array
Working 6 years with this php and never had any problem with php only with a bad script.
It shows not an error message but a blank screen…I’m still trying…and experimenting cause I’m not a professional.

By the way, a copy script with php is working in a same way, I’ll try to find a simalarity
[php]$source_file = ‘…/…/…/data/thumbnail/’ . “$array”; $dest_file = ‘testingdir/’ . “$array1/$array”; copy($source_file, $dest_file); [/php]

Hmm, seems indeed a version problem:

http://stackoverflow.com/questions/1206105/what-does-php-keyword-var-do

What if you do something like this:
[php]
public static function setOriginalDir( $path )
{ self::$originalDir = $path; // Sets a new path
// self::$originalDir .= $path; // Appends the path to the existing originalDir
}
[/php]

When you now require class maxImageUpload you do:
[php]
maxImageUpload::setOriginalDir( $_POST[‘cat’] );
[/php]

Does that help? :wink:

Well, I do not understand the others comments, but, let’s start with the basics…
This line:
// var $originalDir = “…/…/data/original/”.$_POST[‘cat’];//this has to work but it doesn’t
Replace it with these lines for testing and tell us the results…
(First, I have never used “var” in PHP… I use it in Javascript, but, some programmers use it!)

echo $_POST[‘cat’];
origDir= “…/…/data/original/” . $_POST[‘cat’];
Die(“got here…”);

$originalDir = “…/…/data/original/”.$_POST[‘cat’];//this has to work but it doesn’t

This will show you what the posted ‘cat’ variable actually holds.
This will also show you what your “originalDir” looks like.
So, then, you should take the ‘cat’ variable and look at your site in the folder displayed which would be something like “blah/data/original/cat.something”… My guess is that either you have not pointed it to the correct folder or the correct filename… NOTE: this code says to back up two folders and then go into folder data/original… So, if you are in “www.mydomain.com/folder1/folder/2/folder3/index.php”, then you would be looking into “www.mydomain.com/folder1/data/original/cat-filename”… So, it might be a problem with the folder positioning… Also, you are not telling us if the $_POST[‘cat’] is a file or what format that is. Anything could be passed or posted as you did not show us that code… So, good luck!

$_POST[cat] is the name of a numbered folder. The script has to upload an image en put it in a folder named after that number. Images are divided in different numbered folders for each category. So, $_POST[cat], can have a different value

thanks for your answer

Looks to me that you just can’t set a class/object variable to anything non-static.

This will work:
[php]
class bladibla
{ static public $flook = ‘A string’;
static public $narg = 3;
static public $osho = null;

}
[/php]

This won’t:
[php]
class bladibla
{ static public $flook = 'my name is '. $name;
static public $narg = time();
static public $osho = ( $decide ? ‘Yes we can do that’ : ‘No we can’t do that’ );

}
[/php]

And my suggestion earlier was a way to still set those.
[php]
class bladibla
{ static public $flook = ‘’;
static public $narg = 0;
static public $osho = ‘’;

static public function setFlook( $string )
{   self::$flook = $string;
}

static public function setNarg( $num )
{   self::$narg = $num;
}

static public function setOsho( $sthing )
{   self::$osho = $sthing;
}


}
[/php]

And as soon as you require bladibla you do:
[php]
require_once( ‘bladibla.php’ );
bladibla::setFlook( $your_value_here );
bladibla::setNarg( $_POST[‘even_these_will_work’];
bladibla::setOsho( engage( “make it so” ) );

[/php]
good luck ;D

It looks like I’ve to rewrite this script, I think I make a script for each folder…

Waarom dan ?

If you do, you don’t need to rewrite ( or copy ) the entire maxImageUpload class.
Subclass it and only set the originalDir. ( You overload the value in the parentclass )

[php]
class maxImageUpload27 extends maxImageUpload
{ var $originalDir = ‘…/…/data/original/27/’;
}
[/php]

it saves you some typing.
Good luck! ;D

Well, I still think your code should work, I just think there is a level issues. This line:

// var $originalDir = “…/…/data/original/”.$_POST[‘cat’];//this has to work but it doesn’t

Should work, it does for me. But, the following code will not work if the values are not correctly set!

   if (!file_exists($this->originalDir)) {
      mkdir($this->originalDir);
   }

So, you need to change this code to display the values as I mentioned before. Echo and die… Then, you can look at that value and see where the problem lies. For instance , if you try to create a file at dir1/dir2/dir3/27,
you first have to create dir1, then, dir1/dir2, next dir1/dir2/dir3, then dir1/dir2/dir3/27… So, that might be your problem. Not sure if that helps, but, it could be the issue…

Anyway the folders are not the problem. They already there. With the next line the script is working
[php]var $originalDir = ‘/27’;[/php]
The image will be stored in folder 27,
with this
[php]var $originalDir = ‘/’ . “27”;
[/php]or it’s varaiantions the script will show a blank screen
Even with
[php]var $originalDir = ‘/$array’;[/php] or it’s variations the script will create a folder wich I cannot rename of delete

Of course it wouldn’t! You can NOT use an escape character “/” as you did…

This line: var $originalDir = ‘/$array’;

works out like this: $originalDir = ‘$array’;
You can NOT create a folder that starts with a dollar-sign. The escape character “/” is used to force a quote or double-quote to be inserted into the string.
So, this: $xyz="/""; will give you a result of one double-quote going into the string. The escape goes away!

And, this line: var $originalDir = ‘/’ . “27”; causes an odd result… the /’ in the first part equates to taking away the second single quote. so this ends up like : '27 and you can not create a folder spelled like that.

Hope that helps!

Sponsor our Newsletter | Privacy Policy | Terms of Service