Jump to content

[SOLVED] php upload


dezkit

Recommended Posts

Hi how do i do so that the file name will be random, instead of what it is uploaded as?

 

<?php
$path= "uploads/".$HTTP_POST_FILES['ufile']['name'];
if($ufile !=none)
{
if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path))
{
echo "File Upload has been successful.<BR/><BR/>";
echo "<table border=0>";
echo "<tr><td>"; echo "File Name: "; echo "<td>"; echo $HTTP_POST_FILES['ufile']['name'];
echo "<tr><td>"; echo "File Size: "; echo "<td>"; echo $HTTP_POST_FILES['ufile']['size'];
echo "<tr><td>"; echo "File Type: "; echo "<td>"; echo $HTTP_POST_FILES['ufile']['type'];
echo "</table>";
echo "<BR/>Click <a href=\"$path\">here</a> to view the uploaded file.";
}
else
{
echo "Error";
}
}
?>

 

thanks so much

Link to comment
https://forums.phpfreaks.com/topic/126094-solved-php-upload/
Share on other sites

Topic solved, made my own script

 

<?php
function findexts($filename)
{
$filename = strtolower($filename) ;
$exts = split("[/\\.]", $filename) ;
$n = count($exts)-1;
$exts = $exts[$n];
return $exts;
}
global $string;
    $pattern = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
if(empty($length)){
    $length = "10";
    }
for($i=0; $i<$length; $i++){
    $string .= $pattern{rand(0,61)};
    }
    
$ext = findexts($_FILES['ufile']['name']); 
    
$path= "uploads/$string.$ext";
if($ufile !=none)
{
if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path))
{
echo "File Upload has been successful.<BR/><BR/>";
echo "<table border=0>";
echo "<tr><td>"; echo "File Name: "; echo "<td>"; echo "$string.$ext";
echo "<tr><td>"; echo "File Size: "; echo "<td>"; echo $HTTP_POST_FILES['ufile']['size'];
echo "<tr><td>"; echo "File Type: "; echo "<td>"; echo $HTTP_POST_FILES['ufile']['type'];
echo "</table>";
echo "<BR/>Click <a href=\"$path\">here</a> to view the uploaded file.";
}
else
{
echo "Error";
}
}
?>

 

Rate it 1 through 10 guys! :D

Link to comment
https://forums.phpfreaks.com/topic/126094-solved-php-upload/#findComment-652045
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.