Advertisement:

Author Topic: fwrite with osclass  (Read 2796 times)

bilekas

  • Full Member
  • ***
  • Posts: 219
  • Bilekas
fwrite with osclass
« on: August 19, 2011, 08:52:18 am »
Ok guys, so im trying to use the fwrite command to creat a php for file each ItemId..

As it stands i want to pull a php from a folder for each item.. SO

On the item page i have this


Quote
<?php $tuk = osc_item_id().'.php'; ?>

<?php osc_current_web_theme_path('treatments' $tuk) ; ?>

so baically the way the item page is gonna pull them is by the itemid.php - Which is perfect..

Problem is when i come to automatically creating them after itempost.. I need it to create the file with the name"ItemID.php" straight away.

... So far i have this


Quote
                  <?php
$data = $_POST;

$tname = osc_item_id();

$tpath = 'http://www.pamperingpages.co.nz/os-content/modern/treatments/' . $tname . '.php';

if(!file_exists($tpath)){

fwrite ( $tpath );
fclose ( $tpath );

}


Its wrong.. Its not making the file..

Looking for the best route to do it... :(
Help would be HUGELY appreciated right now!

trains58554

  • Osclass contributor
  • Hero Member
  • *****
  • Posts: 3642
  • osCanyon, the class of Osclass
Re: fwrite with osclass
« Reply #1 on: August 19, 2011, 09:09:21 am »
Hi bilekas

You can use this hook to run your script after the item is published.

posted_item : Run when an item is posted. $item is passed as argument

Just wondering what is the point to creating a php file for each item?

Jay

garciademarina

  • Administrator
  • Hero Member
  • *****
  • Posts: 974
Re: fwrite with osclass
« Reply #2 on: August 19, 2011, 01:52:56 pm »
Hi Bilekas,

I miss the fopen call, try this:

Code: [Select]
$data = $_POST;

$tname = osc_item_id();
$tpath = 'http://www.pamperingpages.co.nz/os-content/modern/treatments/' . $tname . '.php';

$fh = fopen($tpath, 'w+') or die("can't open file");

fwrite($fh, "FOOBAR\n");
....

fclose($fh);

Regards

bilekas

  • Full Member
  • ***
  • Posts: 219
  • Bilekas
Re: fwrite with osclass
« Reply #3 on: August 19, 2011, 04:45:43 pm »
Gonna try them now..

The point is each item is gonna have a seperate treatments page which is edited via another script.. Long story and not the way id like to do it but thats how it has to be! :/

bilekas

  • Full Member
  • ***
  • Posts: 219
  • Bilekas
Re: fwrite with osclass
« Reply #4 on: August 20, 2011, 04:51:15 am »
nah the fwrite doesnt seem to be working in the item-post.php file..

Not sure how to correctly add a a hook so any advice is great.. hate to be the burden, especially when i know php.

feel like pooh about the osclass structure and im only realising its sooooo different!

Juan Ramón

  • Osclass Developer
  • Hero Member
  • *****
  • Posts: 2382
Re: fwrite with osclass
« Reply #5 on: August 22, 2011, 12:59:55 pm »
What are you trying to do? Maybe it's some other way to do it.

bilekas

  • Full Member
  • ***
  • Posts: 219
  • Bilekas
Re: fwrite with osclass
« Reply #6 on: August 24, 2011, 02:03:39 am »
im sure there definitely is,

each page will have unique treatments etc etc etc, but they have to be done without adding to the databaase as they are included elsewhere on another site! :/

little bit strange, so the idea i had was that each item would pull its own {itemID}.php file and this would contain the treatments info etc, this way then the php file can also just be recalled to the other site using php include, the problem i was having and stil am actaually is that i need to generate an {itemID}.php file when the item is actually added, and this is where the issues are coming with the fwrite command..

Its a bit awkward most definitely but to be honest it would be a nice feature to have for a lot of other sites which may require unique content.

A Perfect option REALLY would be the ability to seperate the custom fields so that they are not bunched together, but so far as it stands i think this is impossible because of the way the custom fields are in the database.. i cant seem to recall them individually..

For example i cant call my custom field Website and have it in a completely seperate location on the item page as another custom field such as Phone number..

They all have to be Beside eachother..

 This is where the headache is coming.. maybe i will try to write another custom field plugin! :D

"Custom Field 2" :D

_CONEJO

  • Administrator
  • Hero Member
  • *****
  • Posts: 4689
Re: fwrite with osclass
« Reply #7 on: August 24, 2011, 10:55:39 am »
Hi bilekas,

I didn't fully understand your problem, also not sure why you want to have {itemID}.php, but I think this could help.


Quote
A Perfect option REALLY would be the ability to seperate the custom fields so that they are not bunched together, but so far as it stands i think this is impossible because of the way the custom fields are in the database.. i cant seem to recall them individually..

For example i cant call my custom field Website and have it in a completely seperate location on the item page as another custom field such as Phone number..

They all have to be Beside eachother..

That code in item.php display ALL the custom fields from one item together, Is there another way to display them? yes, we need to create some helpers (nice functions) but basically you could retrieve ALL your custom fields with this


$fields 
osc_get_item_meta();


$fields will be an array like this

Code: [Select]
Array (
[0] => Array ( [s_value] => value_of_field_1 [pk_i_id] => 1 [s_name] => field_name_1 [e_type] => DROPDOWN )
[1] => Array ( [s_value] => value_of_field_2 [pk_i_id] => 2 [s_name] => field_name_2 [e_type] => TEXT )
[2] => Array ( [s_value] => value_of_field_3 [pk_i_id] => 3 [s_name] => field_name_3 [e_type] => TEXTAREA )
)


To access an specific value it's a little more complicated:

foreach($fields as $f) {
    if(
$f[pk_i_id]=='THE_ID_WE_ARE_LOOKING_FOR') {
        
// DO CODE HERE
    
}
}



We should definetly create some nice function to work with it.