Hi,

i'm doing an app to manage a music school and i'm inserting instruments and i have to create the program (what do you learn) of the instrument. I'm doing a RichTextBox.
Now i have some problems:

1st - is to save what i write in the richtextbox in a php file.

2nd - is using the top.php and down.php (footer and the banner/menu) as default in every php file i create.

3rd - is it possible i send the php file to my webhost?

4th - how do i create a bulletedlist menu and insert on the textbox?

Hope someone can help me ASAP.

Thank you,
PF2G

It quite simple to write to a text file, in this case a php file.
There are many ways you could do this. This would work for me.

Private Sub CreatePHPFile()
        'First, delete the existing (if any) file.
        If File.Exists(Application.StartupPath & "\filename.php") Then
            File.Delete(Application.StartupPath & "\filename.php")
        End If

        'Create the file stream for writing
        Dim stream As New StreamWriter(Application.StartupPath & "\filename.php", False)

        'Write the initial PHP line
        stream.WriteLine("<?php")

        'Write the include statement for the header
        stream.WriteLine("include_once('top.php');")

        'And now, write out all the lines from the richtextbox
        For Each line As String In rtbTextBox.Lines()
            stream.WriteLine("echo """ & line & """;")
        Next

        'Write the include statement for the footer
        stream.WriteLine("include_once('down.php');")

        'Write the end of the PHP file
        stream.WriteLine("?>)")

        'Flush and close the stream when you're done
        stream.Flush()
        stream.Close()
    End Sub

As for bulleted text and any such formatting.
All you have to do is to insert any html tags before and after the For loop using the stream.WriteLine() method.
The tag for a bulleted list is this: <ul><li>text</li></ul>

As for bulleted text and any such formatting.
All you have to do is to insert any html tags before and after the For loop using the stream.WriteLine() method.
The tag for a bulleted list is this: <ul><li>text</li></ul>

I'm working on the bulleted tex first.
And i have something to say: this program is for people who never worked with html and i want to click on the button and writes the list mark as it appears just like in Word.

If you format the text in the richtextbox with bullets and lists and what not, and wish to "export" the same layout to the php file. Then I cannot help you, because I don't know how.

If you format the text in the richtextbox with bullets and lists and what not, and wish to "export" the same layout to the php file. Then I cannot help you, because I don't know how.

Ok i'll search more about that, thank you.

Now about creating the file do you know i do i do to make something like the OpenDialog but create the file.

If you format the text in the richtextbox with bullets and lists and what not, and wish to "export" the same layout to the php file. Then I cannot help you, because I don't know how.

Is this correct?

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim myStream As Stream
        Dim saveFileDialog1 As New SaveFileDialog()
        'Create the file stream for writing
        Dim stream As New StreamWriter(Application.StartupPath & "\filename.php", False)

        'Write the initial PHP line
        stream.WriteLine("<?PHP")

        'Write the include statement for the header
        stream.WriteLine("include_once('top.php'); ?>")

        'And now, write out all the lines from the richtextbox
        For Each line As String In RichTextBox1.Lines()
            stream.WriteLine("echo """ & line & """;")
        Next

        'Write the include statement for the footer
        stream.WriteLine("<?PHP include_once('down.php');")

        'Write the end of the PHP file
        stream.WriteLine("?>)")

        'Flush and close the stream when you're done
        stream.Flush()
        stream.Close()

        saveFileDialog1.Filter = "PHP files (*.php)|*.php|All files (*.*)|*.*"
        saveFileDialog1.FilterIndex = 2
        saveFileDialog1.RestoreDirectory = True

        If saveFileDialog1.ShowDialog() = DialogResult.OK Then
            myStream = saveFileDialog1.OpenFile()
            If (myStream IsNot Nothing) Then
                ' Code to write the stream goes here.
                myStream.Close()
            End If
        End If
    End Sub

Close. Just switch it around a bit. Like this:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim saveFileDialog1 As New SaveFileDialog()

        saveFileDialog1.Filter = "PHP files (*.php)|*.php|All files (*.*)|*.*"
        saveFileDialog1.FilterIndex = 2
        saveFileDialog1.RestoreDirectory = True

        If saveFileDialog1.ShowDialog() = DialogResult.OK Then
            myStream = saveFileDialog1.OpenFile()
            If (myStream IsNot Nothing) Then
                ' Code to write the stream goes here.
                Dim myStream As Stream

                'Create the file stream for writing
                Dim stream As New StreamWriter(myStream)

                'Write the initial PHP line
                stream.WriteLine("<?PHP")

                'Write the include statement for the header
                stream.WriteLine("include_once('top.php'); ?>")
               
                'And now, write out all the lines from the richtextbox
                For Each line As String In RichTextBox1.Lines()
                   stream.WriteLine("echo """ & line & """;")
                Next

                'Write the include statement for the footer
                stream.WriteLine("<?PHP include_once('down.php');")

                'Write the end of the PHP file
                stream.WriteLine("?>)")

                'Flush and close the stream when you're done
                stream.Flush()
                stream.Close()

                myStream.Close()
            End If
        End If
    End Sub

it works. Thanks a lot.

And how do i make the name of file be copy to a textbox from other Form?

And is it possible i send the php file to my webhost?

I didn't quite catch that. But I assume that you want the filename to be displayed in a textbox on another form.
Use the saveFileDialog1.Filename property and store it in a class variable.
You can then pass that to the constructor, or custom property, of the second form.

You can use FtpWebRequest to transfer files to and from ftp servers.
Here is a FTP client library in C#.

And here is an example of how to use it.

Member Avatar for diafol

Don't understand why vb's made an appearance here...

ANyway:

1st - is to save what i write in the richtextbox in a php file.
2nd - is using the top.php and down.php (footer and the banner/menu) as default in every php file i create.
3rd - is it possible i send the php file to my webhost?
4th - how do i create a bulletedlist menu and insert on the textbox?

1. You want to use this as a text editor for creating webpages or just editing 'articles' once the site is up? If you want it for the first scenario, don't bother - use something else. But if you really have to, follow:

a) put RTB into a form with a submit button
b) accept the $_POST data and either write it to a file with file_put_contents() or to a DB

2.

every file:

include('top.php');

...rest of page...

include('bottom.php');

3. FTP - as already covered

4. What editor are you using? Any wysiwyg editor worth its salt will have these buttons, e.g. TinyMCE, CKEditor etc.

Don't understand why vb's made an appearance here...
ANyway:
1. You want to use this as a text editor for creating webpages or just editing 'articles' once the site is up? If you want it for the first scenario, don't bother - use something else. But if you really have to, follow:

I want to create webpages which is already done.

3. FTP - as already covered
4. What editor are you using? Any wysiwyg editor worth its salt will have these buttons, e.g. TinyMCE, CKEditor etc.

The FTP part is giving me some trouble because every code i find are different and i need some imports that i don't know what are the ones i need.
About the editor i'm not using any WYSIWYG...

Member Avatar for diafol

I want to create webpages which is already done.

So you don't need this any more if it's already done?
If you're not using a wysiwyg - you'll just be using a normal textarea, with buttons to add html to the text in the textarea - which will be visible to the user. Is that what you want?

In short I have no idea what you're trying to do with this editor. Is this editor supposed to be online or not? If not, use a good old editor/IDE like Bluefish, Notepad++, Aptana, Eclipse etc.

FTP
You should have been given ftp connection details with your hosting account. Try downloading FileZilla FTP Client. Use the connection details to connect to your remote site. Then it's a question of synching the two locations to upload your files.
If you don't know or have lost these connection details, contact your host. If you have a cPanel (some cheap hosts may not include this in their basic packages), then you can set up FTP accounts through that.

I don't know why this thread was moved to PHP area.

I'm doing an app in Visual Basic 2008. i'm doing a form where administration can add instruments/courses to the school and when the admin add a course they have to add the program (what do you learn at that course), so my question is on the program creating.

i'm doing a form with a RichTextBox and a button with SaveFileDialog - the file created is saved in .php, then when i press "Ok" the php file is sent to my webhost, via FTP.

Got it?

Member Avatar for diafol

AHA! That explains the VB stuff! Got it. That wasn't clear from your first post as the context was PHP Forum.

Blame the MOD! :)

OK, I will leave you alone now.

I got this code in PHP, can someone help me?

<?php
session_start();

	require "../incluir/geral.php";
    require_once "../incluir/conexao.php";

$loc=$_POST['local'];
$lnk=$_POST['link'];

	if (isset($_FILES["logo"])){
		$arquivo = isset($_FILES["logo"]) ? $_FILES["logo"] : FALSE;
        $config = array();
        $config["tamanho"] = 906883;
        $config["largura"] = 6000;
        $config["altura"] = 5000;
        $config["diretorio"] = "../banners/";
        function nome($extensao){
            global $config;
            $temp = substr(md5(uniqid(time())), 0, 10);
            $imagem_nome = $temp . "." . $extensao;
            if(file_exists($config["diretorio"] . $imagem_nome)) {$imagem_nome = nome($extensao);}
            return $imagem_nome;
        }
        if($arquivo){
            $erro = array();
            if(!eregi("^image\/(pjpeg|jpeg|png|gif|bmp)$", $arquivo["type"]))
            {$erro[] = "Arquivo em formato inválido! A imagem deve ser jpg, jpeg, bmp, gif ou png. Envie outro arquivo";
            }else{
                if($arquivo["size"] > $config["tamanho"])
                {$erro[] = "Arquivo em tamanho muito grande! A imagem deve ser de no máximo " . $config["tamanho"] . " bytes. Envie outro arquivo";}
                $tamanhos = getimagesize($arquivo["tmp_name"]);
                if($tamanhos[0] > $config["largura"])
                {$erro[] = "Largura da imagem não deve ultrapassar " . $config["largura"] . " pixels";}
                if($tamanhos[1] > $config["altura"])
                {$erro[] = "Altura da imagem não deve ultrapassar " . $config["altura"] . " pixels";}
            }
            if(!sizeof($erro)){
                preg_match("/\.(gif|bmp|png|jpg|jpeg){1}$/i", $arquivo["name"], $ext);
                $imagem_nome = nome($ext[1]);
                $imagem_dir = $config["diretorio"] . $imagem_nome;
                move_uploaded_file($arquivo["tmp_name"], $imagem_dir);
			    $Result1 = mysql_query("insert into banners (bnr_imagem, bnr_pos, bnr_link) values ('$imagem_nome', '$loc', '$lnk')", $conexao) or die(mysql_error());
			}else{ 
                echo "<tr><td colspan=2 bgcolor=red><B><U>Ocorreu(am) o(s) seguinte(s) erro(s):</u><BR>";
                foreach($erro as $err){echo " - " . $err . "<BR>";}
                echo "</B></td></tr>";
				exit;
            }

        }
	}

	header("Location: banners.php");
?>

Help you do what?
If you have problem with this code, then perhaps you should ask your teacher about it.

After all the code my teacher lent to me was to send by website.

Now the code Oxiegen gave me it's cool but i need the Imports Utilities.FTP, which i need some kind of plugin to Visual Basic.

Can someone help me?

By referencing the compiled C# library, you WILL get access to Utilities.FTP.

Follow these three steps...
1) Compile the FTP class library!
2) Create a reference to the DLL file in your own project!
The DLL file is located inside the \bin folder of THAT project.
3) Use: Imports Utilities.FTP.

It's that simple.
There is no need to look for and install any third-party software.

By referencing the compiled C# library, you WILL get access to Utilities.FTP.

Follow these three steps...
1) Compile the FTP class library!
2) Create a reference to the DLL file in your own project!
The DLL file is located inside the \bin folder of THAT project.
3) Use: Imports Utilities.FTP.

It's that simple.
There is no need to look for and install any third-party software.

I'm not using C#, i'm using Visual Basic 2008. And i don't find any FTP library...

The link I gave you to a forum discussion at MSDN contained another link pointing to a project at CodeProject.
THAT project is written in C#.
Download it, open it in Visual Studio and compile it.
That will produce a library that you need to reference in your own project.

When that is done, you can use "Import Utilities.FTP".

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.