Jump to content
php.lv forumi

vienkars file uploads..


blondine

Recommended Posts

izrkanjaajos pa php un google.. un neko jedzigu neatradu , lai gan pilns nets ar drazu.. bet paraleeli uzjautaasu - interesee vienkars file uploads, visticamaaak *jpg, *png, *flv vairaak vai mazaak.. (vairaak domaats kaa papildmaterials noteiktam rakstam)

un varbut kaadi ieteikumi, ierosinajumi , thx =)

Link to comment
Share on other sites

if(@move_uploaded_file($_FILES[$upload_name]['tmp_name'], $target)){
    echo "There was a problem with the upload";
}else {
    echo "Sorry, there was a problem uploading your file.";
}

Tāpēc ka te ir drukas kļuda , abi paziņojumi saka ka upload's nav izdevies.

Link to comment
Share on other sites

Tu jau saproti, ka šajā vietā tev $upload satur objektu ar tukšiem, vai ar kaut kādiem defaultajiem parametriem?

$upload = new Upload();
$foto = $upload->getFilenameFoto();

 

Izdrukā var_dump($upload); un apskaties, ko kurā brīdī viņš satur.

Link to comment
Share on other sites

nu protams, jo tajās metodēs ir dažādas upload klases instances

 

uztaisi klases globālo mainīgo(laikam tā to sauc)

 

http://php.net/manual/en/language.oop5.php tur daudz visādi piemēri

 

edit:

 

ops izskatās ka vienkārši katrā metodē tiek taisīta jauna instance :)

Edited by php newbie
Link to comment
Share on other sites

Es jau saprotu, ka taa ir pagaatne un taa, bet var jau sho to palasiit pirms raksta lietas :/ Tev tak nav ne mazaakaa saprashana par OOP. Raksti proceduraali - kam tev uzspiest OOP?

 

new Upload() tev izveido jaunu OBJEKTU - viss ko tu saglabaaji kaadaa citaa objektaa tev nebuus pieejams. Domaa par to, kaa tas ir cits masiivs, kursh nekaadaa veidaa nav saistiits ar pirmo masiivu. Vieniigaa kopiigaa lieta, ka tu vari lietot taas pashas metodes un izmantot tos mainiigos (bet veertiibas buus citas). Atkal kaa jau masiivs. Vari izmantot visas array_pop, array_diff metodes un likt klaat jaunas veertiibas klaat masiivaa, bet taas nekaadaa veidaa nesinhronizeejas.

 

Protams vienmeer jau var izmantot statiskas metodes un propertijus, bet ja viss tiks taisiits tieshi taa, tad kaada jeega no OOP?

class Upload {
 private static $file_name;

 public static function set_file_name($file_name) {
   self::$file_name = $file_name;
 }

 public static function get_file_name() {
   return self::$file_name;
 }
}

class History {
 public function save() {
   $foto = Upload::get_file_name();
 }
}

Upload::set_file_name('learn_stuff.gif');

$history = new History;
$history->save();

 

Ja gribi izmantot objektu tad:

 

 

class Upload {
 private $file_name;

 public function set_file_name($file_name) {
   $this->file_name = $file_name;
 }

 public function get_file_name() {
   return $this->file_name;
 }
}

class History {
 public function save($upload) {
   $foto = $upload->get_file_name();
 }
}

$upload = new Upload;
$upload->set_file_name('learn_stuff.gif');

$history = new History;
$history->save($upload);

 

Mantoshanu vajag izmantot, ja tieshaam vajag kaut ko mantot nevis padot mainiigo...

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...