Кофти проблем при ъплоуд!

oniq

Registered
Ето какво кодче спретнах...

Код:
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
 <form action="" method="post" enctype="multipart/form-data">
 <input type="file" name="file"> <input type="submit" name="upload_file" value="Качи">
 </form>
 
<?php

function UploadFile($fileimg, $filetype, $filetmp, $filesize, $opentype, $patch) {
  
if ($filesize == NULL) {
echo "No file";
}
else {

if (!in_array($filetype, $opentype)) {
echo "error Format";
}
else {
if (file_exists($patch.$fileimg)) {
echo " exists file";
}
else {
$randname = rand(1000,9000);
$renamen = rename($fileimg, $randname);
if ($renamen) {
move_uploaded_file($filetmp, $patch.$renamen);
}

}
}
}
}
// -----END FUNCTION UploadFile--------- //


if ($_POST['upload_file']) {
$fileimg = $_FILES['file']['name'];
$filetype = $_FILES['file']['type'];
$filetmp = $_FILES['file']['tmp_name'];
$filesize = $_FILES['file']['size'];

$opentype = array("image/gif", "image/jpg", "image/jpeg", "image/png");
$patch = "images/";
UploadFile($fileimg, $filetype, $filetmp, $filesize, $opentype, $patch);

}

?>

Проблема е там, че когато искам да ъплоудна снимка ми дава следната грешка...

Код:
Warning: rename(othvurlena.gif,1462) [function.rename]: No such file or directory in C:\xampp\htdocs\urok\index.php on line 24

Нещо функцията rename() не се получава :idea:
 
Нямам идея как ще стане... слагах тва..

Код:
$randname = rand(1000,9000);
rename($patch.$fileimg, $randname);

къде ли не!
 
Код:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> 
<form action="" method="post" enctype="multipart/form-data"> 
<input type="file" name="file"> 
<input type="submit" name="upload_file" value="asd"> 
</form> 

<?php 

function UploadFile($fileimg, $filetype, $filetmp, $filesize, $opentype, $patch) { 
$randname = rand(1000,9000); 
$file_ext = strtolower(substr($fileimg,strrpos($fileimg,"."))); 
$filen =$randname.$file_ext;
if ($filesize == NULL) { 
echo "No file"; 
} 
else { 

if (!in_array($filetype, $opentype)) { 
echo "error Format"; 
} 
else { 
if (file_exists($patch.$filen)) { 
echo " exists file"; 
} 
else { 
move_uploaded_file($filetmp, $patch.$filen);  

} 
} 
} 
} 
// -----END FUNCTION UploadFile--------- // 


if ($_POST['upload_file']) { 
$fileimg = $_FILES['file']['name']; 
$filetype = $_FILES['file']['type']; 
$filetmp = $_FILES['file']['tmp_name']; 
$filesize = $_FILES['file']['size']; 

$opentype = array("image/gif", "image/jpg", "image/jpeg", "image/png"); 
$patch = "images/"; 
UploadFile($fileimg, $filetype, $filetmp, $filesize, $opentype, $patch); 

} 

?>
ето тека би трябвало да работи не сам го тествал

//Edit

Прочетох грешката и тя идва от там че фаила още не е качен а то го търси да го rename


тествах кода работи
 

Горе