fopen

Secţiune dedicată începatorilor.

Moderatori: Moderatori, Start Moderator


Pirahna
Senior Member
Mesaje: 5985
Membru din: Dum Aug 22, 2004 2:04 am
Localitate: la birou
Contact:

Mesajde Pirahna » Sâm Noi 17, 2007 10:59 pm

|

afro
PHPRomania Supporter
Mesaje: 18
Membru din: Lun Oct 29, 2007 1:31 pm

Mesajde afro » Sâm Noi 17, 2007 11:08 pm

e doar o parte din cod. Ideea e ca am un form cu un textfield si vreau sa imi creeze un director si un fisier index.html, in fisierul index.html sa bag printre altele si textul din textfield. in $ccode e numele directorului generat dintr-o functie random.

function generateCode($length=3) {
$chars = "abcdefghijklmnopqrstuvwxyz";
$code = "";
$clen = strlen($chars) - 1;
while (strlen($code) < $length) {
$code .= $chars[mt_rand(0,$clen)];
}
return $code;
}
$text1 = $_POST['textfield'];
$ccode = generateCode();
$dir = "/subdomains/test/httpdocs/".$ccode."";

include("nimic.php");

$conn_id = ftp_connect($ftp_server);

$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

if (ftp_mkdir($conn_id, $dir)) {
echo "successfully created $dir\n";
$temp = tmpfile();
ftp_fput($conn_id, "/subdomains/test/httpdocs/".$ccode."/index.html", $temp, FTP_ASCII);

ftp_site($conn_id, "CHMOD 0777 /subdomains/test/httpdocs/".$ccode."/index.html");

$fp = fopen("ftp://user:parola@ftp.24x7Tips.com/subdomains/test/httpdocs/".$ccode."/index.html", "w") or die("Eroare deschidere");
fputs($fp,"Test");
fclose($fp);

ftp_site($conn_id,"CHMOD 0644 /subdomains/test/httpdocs/".$ccode."/index.html");
} else {
echo "There was a problem while creating $dir";
}

Pirahna
Senior Member
Mesaje: 5985
Membru din: Dum Aug 22, 2004 2:04 am
Localitate: la birou
Contact:

Mesajde Pirahna » Sâm Noi 17, 2007 11:28 pm

pai si ce naiba faci cu ftp-ul ala ?
|

afro
PHPRomania Supporter
Mesaje: 18
Membru din: Lun Oct 29, 2007 1:31 pm

Mesajde afro » Sâm Noi 17, 2007 11:40 pm

$fp = fopen("/subdomains/test/httpdocs/".$ccode."/index.html", "w") or die("Eroare deschidere");

Pai asa era ideea, dar am incercat cu ftp, pentru ca habar n-am cum sa ajung la fisierul ala. Aia e structura directoarelor (/subdomains/test/httpdocs/director_nou/index.html) si am zis ca daca am creat directoarele si fisierele html prin ftp sa incerc sa si deschid prin ftp. Spui ca n-am permisiune sa deschid, pai chmod 0777 nu imi da voie sa scriu ?

Pirahna
Senior Member
Mesaje: 5985
Membru din: Dum Aug 22, 2004 2:04 am
Localitate: la birou
Contact:

Mesajde Pirahna » Sâm Noi 17, 2007 11:55 pm

ia vezi ce face $_SERVER['DOCUMENT_ROOT'] ...
poate iti dai seama ca solutia se rezolva foarte usor din fopen / fwrite ...
|

afro
PHPRomania Supporter
Mesaje: 18
Membru din: Lun Oct 29, 2007 1:31 pm

Mesajde afro » Dum Noi 18, 2007 12:02 am

De asta aveam nevoie. Mersi mult :lol:

afro
PHPRomania Supporter
Mesaje: 18
Membru din: Lun Oct 29, 2007 1:31 pm

Mesajde afro » Lun Noi 19, 2007 12:51 am


Pirahna
Senior Member
Mesaje: 5985
Membru din: Dum Aug 22, 2004 2:04 am
Localitate: la birou
Contact:

Mesajde Pirahna » Lun Noi 19, 2007 1:26 am

|

afro
PHPRomania Supporter
Mesaje: 18
Membru din: Lun Oct 29, 2007 1:31 pm

Mesajde afro » Mar Noi 20, 2007 11:10 am



Înapoi la “PHP Incepători”

Cine este conectat

Utilizatori ce ce navighează pe acest forum: Niciun utilizator înregistrat și 7 vizitatori