Ahoj vsetcia som tu novy... mam taky problem... hladal som ci tu uz niekde nieje spomenuty ale nic som nensiel,takze snad nie
. Mam dva scripty ktore zabezpecuju upload na moju stranku... a mali by subory ukladat s random menami ... ale ani jeden mi nefunguje , mohol by mi prosim niekto poradit? diki
Script1:
<?php
$target = "upload/";
$target = $target . basename( $_FILES['uploaded']['name']) ;
$ok=1;
//This is our size condition
if ($uploaded_size > 350000)
{
echo "Your file is too large.<br>";
$ok=0;
}
//This is our limit file type condition
if ($uploaded_type =="text/php")
{
echo "No PHP files<br>";
$ok=0;
}
//Here we check that $ok was not set to 0 by an error
if ($ok==0)
{
Echo "Sorry your file was not uploaded";
}
//If everything is ok we try to upload it
else {
$nazov_novy=$_FILES['uploaded']['name'];
while(file_exists("upload/".$nazov_novy)){
$nazov_novy=$nazov_novy."_".rand(1,9999999);
}
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], "upload/".$nazov_novy))
{
echo "The file ".basename( $_FILES['uploadedfile']['name']). " has been uploaded";
} else {
echo "Sorry, there was a problem uploading your file.";
}
}
?>
skript2:
<?php
$target = "upload/";
$ext = explode('.',$_FILES['userfile']['name']);
$ext = $ext[count($ext)-1];
$rand = rand(11111,99999);
$file = $rand . "." .$ext;
$target = $target . $file ;
$ok=1;
/*This is our size condition
if ($uploaded_size > 350000)
{
echo "Your file is too large.<br>";
$ok=0;
}
*/
//This is our limit file type condition
if ($ext !="gif" && $ext !="jpg" && $ext !="jpeg" && $ext !="mid" && $ext !="mp3" && $ext !="amr" && $ext !="png")
{
echo "No valid extension<br>";
$ok=0;
}
//Here we check that $ok was not set to 0 by an error
if ($ok==0)
{
Echo "Sorry your file was not uploaded";
}
//If everything is ok we try to upload it
else
{
if(move_uploaded_file($_FILES['userfile']['tmp_name'], $target))
{
echo "The file has been uploaded. Your ID number is: $rand";
}
else
{
echo "Sorry, there was a problem uploading your file.";
}
}
?>