Pogledajte određenu poruku
Staro 07. 03. 2014.   #1
stanke
član
Certified
 
Datum učlanjenja: 06.09.2012
Poruke: 64
Hvala: 0
342 "Hvala" u 10 poruka
stanke is on a distinguished roadstanke is on a distinguished roadstanke is on a distinguished roadstanke is on a distinguished road
Default upload picture

Radim Upload slike u folder aplikacija radi ali mi se prvi put kad otvorim stranicu prikazu par kodova kao greska kad uplodujem prvu sliku onda sve radi normalno nema gresaka, mogu da uplodujem neprekidno sve dok ne izadjem sa te stranice pa ponovo kad kliknem na nju desi se isto prvi put greska posle normalno radi.
imam folder images
index.php falj koji sadrzi:

<?php
include_once 'classimage.php';
$img= new images();

$img->uploadImages();

?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
<form action="index.php" method="post" enctype="multipart/form-data">
<input type="file" name="picture" >
<br><br>

<input type="submit" name="upload" value="Upload Picture">
</form>
</body>

</html>


i classimage.php stranicu koja sadrzi:


<?php
class images
{
protected $fileName;
protected $fileTmp;
protected $fileType;
protected $fileSize;
protected $fileError;

public function __construct()
{
$this->fileName = $_FILES['picture']['name'];
$this->fileTmp = $_FILES['picture']['tmp_name'];
$this->fileSize = $_FILES['picture']['size'];
$this->fileError = $_FILES['picture']['error'];
$this->fileType =$_FILES['picture']['type'];
}

public function uploadImages()
{
//if Button push
if(isset($_POST['upload']) && $_POST['upload']=='Upload Picture')
{
//get type after .
$kabom = explode(".", $this->fileName);
//get image type
$fileExtnsion = end($kabom);
$fileName = time().rand().".".$fileExtnsion;

if(!$this->fileTmp)
{
echo "Error: Please browse for a file before clicking the upload button";
exit();
}
elseif ($this->fileSize > 5242880)
{
echo "Error: Your file was large than 5MB";
unlink($this->fileTmp);
exit();
}
elseif (!preg_match("/.(gif|jpg|png)$/i", $this->fileName))
{
echo "ERROR: Your image was not .gif, .jpg, or .png.";
unlink($this->fileTmp);
exit();
}


elseif ($this->fileError==1)
{
echo "Error.Please try again";
exit();
}
$movePicture = move_uploaded_file($this->fileTmp, "images/$fileName");
if($movePicture == false)
{
echo "Error File not uploaded.";
exit();
}
}
}
}
?>

Problem mi je jedino sto se samo prvi put kad godudjem na stranicu pojavi greska :

Notice: Undefined index: picture in C:\xampp\htdocs\www\imageupload\test\classimage.ph p on line 12

Notice: Undefined index: picture in C:\xampp\htdocs\www\imageupload\test\classimage.ph p on line 13

Notice: Undefined index: picture in C:\xampp\htdocs\www\imageupload\test\classimage.ph p on line 14

Notice: Undefined index: picture in C:\xampp\htdocs\www\imageupload\test\classimage.ph p on line 15

Notice: Undefined index: picture in C:\xampp\htdocs\www\imageupload\test\classimage.ph p on line 16

ova greska se odnosi na kod iz klase

$this->fileName = $_FILES['picture']['name']; - linija 12
$this->fileTmp = $_FILES['picture']['tmp_name']; - linija 13
$this->fileSize = $_FILES['picture']['size']; - linija 14
$this->fileError = $_FILES['picture']['error']; - linija 15
$this->fileType =$_FILES['picture']['type']; - linija 16
stanke je offline   Odgovorite uz citat