Jump to content

upload a few files and then have them rename with rand()?


SnakZ

Recommended Posts

I have 2 sites here that does what i need them to do but i dont know how to put the 2 codes together 

 

i got it to upload all files and used rand() to give the files a # but it ends up giving them all the same # lol so they overwrite them selfs lol

 

 

This site shows how to upload mltiple fiels with php.

http://www.ehow.com/how_6345068_upload-multiple-files-php.html

 

 

This site shows how to rename only 1 file uploaded with rand()

http://php.about.com/od/advancedphp/ss/rename_upload.htm

 

 

i pray this is not to hard to do and if any one gets bored after words can you show how to block a file type from being

uploaded ? like php/exe types

 

PS)i would call my self a php newbe lol and ty you for your time and help

 

Code from http://php.about.com/od/advancedphp/ss/rename_upload.htm

 

<form enctype="multipart/form-data" action="upload.php" method="POST"> 
Please choose a file: <input name="uploaded" type="file" /><br /> 
<input type="submit" value="Upload" /> 
</form> 


//This function separates the extension from the rest of the file name and returns it  
function findexts ($filename) 
{ $filename = strtolower($filename) ; 
$exts = split("[/\\.]", $filename) ; 
$n = count($exts)-1; $exts = $exts[$n]; 
return $exts; 
} 

//This applies the function to our file  
$ext = findexts ($_FILES['uploaded']['name']) ;

//This line assigns a random number to a variable. You could also use a timestamp here if you prefer.  
$ran = rand () ; 
//This takes the random number (or timestamp) you generated and adds a . on the end, so it is ready of the file extension to be appended. 
$ran2 = $ran."."; 
//This assigns the subdirectory you want to save into... make sure it exists! 
$target = "images/";
//This combines the directory, the random file name, and the extension 
$target = $target . $ran2.$ext; 
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { 
echo "The file has been uploaded as ".$ran2.$ext; } 
else { 
echo "Sorry, there was a problem uploading your file."; 
}

The code from http://www.ehow.com/how_6345068_upload-multiple-files-php.html

 

<form action="upload.php" method="post" enctype="multipart/form-data">
File: <input type="file" name="file[]"/><br/>
File: <input type="file" name="file[]"/><br/>
File: <input type="file" name="file[]"/><br/>
<input type="submit" name="submit" value="Upload"/>
</form>



$destpath = "upload/" ;


while(list($key,$value) = each($_FILES["file"]["name"])) {
if(!empty($value)){
f ($_FILES["file"]["error"][$key] > 0) {
echo "Error: " . $_FILES["file"]["error"][$key] . "<br/>" ;
}
else {
$source = $_FILES["file"]["tmp_name"][$key] ;
$filename = $_FILES["file"]["name"][$key] ;
move_uploaded_file($source, $destpath . $filename) ;
echo "Uploaded: " . $destpath . $filename . "<br/>" ;
}
}
}

Link to comment
Share on other sites

Is a few ways to go about this.

 

Giving them a random number, well.....eventually it will give the file the same number,but here is the code for that.

 

$random_number = rand(1,50000)-1;//change 50000 to max number you would like

 

If you truly want unique, rename the file with a md5 of the name of the file.

 

$md5_image = md5($image_name.jpg);

 

I suggest saving these values as you can't reverse the md5, so set a database and save the md5 image value if need to reference it in some way, if it's just displaying the images what I do for my thumbserver is on the order of this.

 

 

I go by the url of the website, convert url to md5 value,then save it as a md5 with png extension.

 

http://www.computech.net/  becomes aa5f43bb38e109925f4cb23ea7046d8c

 

So the image would then be aa5f43bb38e109925f4cb23ea7046d8c.png

 

 

Now here's a bit of code to show how i find it, I really suggest saving these values, in my case I do not, I let it search for multiple values and give me a match, otherwise get the image through firefox, but lets not get into that process.

 

$image_value = "http://www.computech.net/";//this could be a variable versus this website
$image_md5 = md5($image_value);//convert to md5
$image_location = "./thumb/$image_md5.png";//folder images are saved andadd the md5 plus extension

//see if file exists , if does use it, if not do something else 
if (file_exists($image_location)) {
    $source_image = $image_location;
} else {
$source_image = "Some alternate image or message";
}

Link to comment
Share on other sites

I thought more about this.

 

Just make it timestamp

 

$timestamp = "date('Y-m-d H:i:s')";
$image_value = "$timestamp.$ext";

 

 

Please choose a file: <input name="uploaded" type="file" /><br />

<input type="submit" value="Upload" />

</form>

 

 

//This function separates the extension from the rest of the file name and returns it

function findexts ($filename)

{ $filename = strtolower($filename) ;

$exts = split("[/\\.]", $filename) ;

$n = count($exts)-1; $exts = $exts[$n];

return $exts;

}

 

//This applies the function to our file

$ext = findexts ($_FILES['uploaded']['name']) ;

 

//This line assigns a timestamp.

$timestamp = "date('Y-m-d H:i:s')";

//This takes the timestamp you generated and adds a . on the end, so it is ready of the file extension to be appended.

$timestamp = $timestamp".";

//This assigns the subdirectory you want to save into... make sure it exists!

$target = "images/";

//This combines the directory, the random file name, and the extension

$target = "$target$timestamp$ext";

if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) {

echo "The file has been uploaded as "$timestamp$ext; }

else {

echo "Sorry, there was a problem uploading your file.";

}

Link to comment
Share on other sites

now what would i do if i wanted to download more then one file at a time ? that what i was having a hard time with

at this point in time the only code i found that will work is

 

$ext = findexts  ($_FILES['file']['name']) ;
$ran = rand () ; 
$ran2 = $ran."."; 
$target = "upload/";
$target = $target . $ran2.$ext;
if(move_uploaded_file($_FILES['file']['tmp_name'], $target)) { 
echo "<BR>The file has been uploaded as ".$ran2.$ext; 
} else { 
echo "Sorry, there was a problem uploading your file.<br>"; 
}
///////////////////////////////////////////////////
$ext2 = findexts  ($_FILES['file2']['name']) ;
$ran2 = rand () ; 
$ran22 = $ran2."."; 
$target = "upload/";
$target = $target . $ran22.$ext2; 
if(move_uploaded_file($_FILES['file2']['tmp_name'], $target)) { 
echo "<BR>The file has been uploaded as ".$ran22.$ext2; 
} else { 
echo "Sorry, there was a problem uploading your file.<BR>"; 
}
//////////////////////////////////////////////////
$ext3 = findexts  ($_FILES['file3']['name']) ;
$ran3 = rand () ; 
$ran23 = $ran3."."; 
$target = "upload/";
$target = $target . $ran23.$ext3; 
if(move_uploaded_file($_FILES['file3']['tmp_name'], $target)) { 
echo "<BR>The file has been uploaded as ".$ran23.$ext3; 
} else { 
echo "Sorry, there was a problem uploading your file.<BR>"; 
}
//////////////////////////////////////////////////

 

and this is only to upload 3 files lol every time i have to add a new set of lines

but now im having a hard time with puting the names into the SQL i was thinking using

$uploaded_video=$_POST['$ran2.$ext'];

would work but the $ran2.$ext just sends it back to the rand() and give me back a new # lol

even after that it still didnt put the name into the database not sure why yet

Link to comment
Share on other sites

Well actually I rewrote this into a more usable thing. I added the image source display, but can remove it.

 

I must advise you should be having checks for max filesize and types.

 

<?php

$timestamp = time();;
$destpath = "images/";
$target = "$target$the_file";

while(list($key,$value) = @each($_FILES["file"]["name"])) {
if(!empty($value)){
if ($_FILES["file"]["error"][$key] > 0) {
echo "Error: " . $_FILES["file"]["error"][$key] . "<br/>" ;
}
else {
$file_name = $timestamp.$_FILES['file']['name'];

$source = $_FILES["file"]["tmp_name"][$key] ;
$filename = $_FILES["file"]["name"][$key];
$filename = strtolower($filename);
$filename = "$timestamp$filename";
move_uploaded_file($source, $destpath . $filename) ;
$final_file_location = "$destpath$filename";
echo "Uploaded to: $final_file_location<br/>";
//just remove the image source code below if not for images
?>
<h2><a href="<?php echo $final_file_location; ?>" target="_blank"><img src="<?php echo $final_file_location; ?>" border="0"></a></h2>
<?php
}
}
}
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) {
echo "The file has been uploaded as $filename";
} else {
echo "Upload your file.";
}

?>

<form action="upload.php" method="post" enctype="multipart/form-data">
File: <input type="file" name="file[]"/><br/>
File: <input type="file" name="file[]"/><br/>
File: <input type="file" name="file[]"/><br/>
<input type="submit" name="submit" value="Upload"/>
</form>

Link to comment
Share on other sites

yeah i been looking into trying to find a way to say what types  but not sure yet as to how to put them in or at what point in the coding to put it in

and i seen people saying there more then one type of code to do this a mime and a "if"  ?

 

and ty you for your help with the coding it works great its way better then what i came up with lol

 

now i know this is how you stop files types but not sure what to put in the { } to make the file stop uploading

$ext = findexts ($_FILES['photo']['name']) ;
if ($ext=="pdf" || $ext=="gif" || $ext=="jpeg" || $ext=="jpg" || $ext=="png") 
{ 
echo "files are not allowed!</div>"; 
}  
[code]

now this works on this code but on the code you have listed im not sure yet as to where the "$ext" part is on ur code lol

Link to comment
Share on other sites

what im trying to do is take the files name and put them into SQL

so i can pull them up on other parts of the site but i dont know how as u already lost me lol

for me to do it i would need to find a way to get the files new names

so i can put them where i need to in SQL

SQL is something like "title , upload_1, upload_2, upload_3, upload_4, upload_5"

need to put the name where the upload is in the same order as they was uploaded what i pray is not to much of a pain lol

 

not sure how to put it into the while loop or the array part sorry

 

 

Link to comment
Share on other sites

What exactly are you trying to make here.

 

I understand would like to save the values, but for what reason.

 

This gonna be a large thumbnail gallery, individual posts per image, will there be users areas or folders, categories. It's some things should consider and have a plan for this.

 

Sure can do some sql insertions going by auto increment and id numbers, title,description,image location

Link to comment
Share on other sites

http://www.shadowmastersz.net/modules.php?name=Videos

 

its a php-nuke type of page that shows videos one part is for people to see and other part is for admins

the part for people

when they like to see a video (anime video) its better to show more then one link for a video

the mod is set up to show the Series and from there u pick what episode you would like to see  (here comes the part of uploading)ones your on the episode page it pulls data from the database what is the data for the videos from text, title, video Embed, and then shows them  below is how the page is set up (it may not be the best set up for something like this lol but for now it works) (sorry if my coding looks bad :D )

$text

$video_url

$uploaded_video

$text_2

$video_url_2

$uploaded_video_2

$text_3

$video_url_3

$uploaded_video_3

$text_4

$video_url_4

$uploaded_video_4

$text_5

$video_url_5

$uploaded_video_5

 

//////////1 start/////////////
if ($text)
{
print "$text<BR><BR>";
}
if ($video_url)
{
print "$video_url<BR><BR>";}
if ($uploaded_video)
{
print "<object id=\"MediaPlayer1\" CLASSID=\"CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95\" codebase=\"http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701\"
standby=\"Loading Microsoft Windows® Media Player components...\" type=\"application/x-oleobject\" width=\"640\" height=\"481\">
<param name=\"fileName\" value=\"modules/$module_name/uploaded_videos/$uploaded_video\">
<param name=\"animationatStart\" value=\"true\">
<param name=\"transparentatStart\" value=\"true\">
<param name='autoStart' value=\"false\">
<param name=\"showControls\" value=\"true\">
<param name=\"Volume\" value=\"-450\">
<embed type=\"application/x-mplayer2\" pluginspage=\"http://www.microsoft.com/Windows/MediaPlayer/\" src=\"modules/$module_name/uploaded_videos/$uploaded_video\" name=\"MediaPlayer1\" width=\"640\" height=\"481\" autostart=1 showcontrols=1 volume=-450>
</object><BR><BR>";}
////////1 end/////////////////

//////////2 start/////////////
if ($text_2)
{
print "$text_2<BR><BR>";
}
if ($video_url_2)
{
print "$video_url_2<BR><BR>";}
if ($uploaded_video_2)
{
print "<object id=\"MediaPlayer1\" CLASSID=\"CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95\" codebase=\"http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701\"
standby=\"Loading Microsoft Windows® Media Player components...\" type=\"application/x-oleobject\" width=\"640\" height=\"481\">
<param name=\"fileName\" value=\"modules/$module_name/uploaded_videos/$uploaded_video_2\">
<param name=\"animationatStart\" value=\"true\">
<param name=\"transparentatStart\" value=\"true\">
<param name='autoStart' value=\"false\">
<param name=\"showControls\" value=\"true\">
<param name=\"Volume\" value=\"-450\">
<embed type=\"application/x-mplayer2\" pluginspage=\"http://www.microsoft.com/Windows/MediaPlayer/\" src=\"modules/$module_name/uploaded_videos/$uploaded_video_2\" name=\"MediaPlayer1\" width=\"640\" height=\"481\" autostart=1 showcontrols=1 volume=-450>
</object><BR><BR>";}
////////2 end/////////////////
//////////3 start/////////////
if ($text_3)
{
print "$text_3<BR><BR>";
}
if ($video_url_3)
{
print "$video_url_3<BR><BR>";}
if ($uploaded_video_3)
{
print "<object id=\"MediaPlayer1\" CLASSID=\"CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95\" codebase=\"http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701\"
standby=\"Loading Microsoft Windows® Media Player components...\" type=\"application/x-oleobject\" width=\"640\" height=\"481\">
<param name=\"fileName\" value=\"modules/$module_name/uploaded_videos/$uploaded_video_3\">
<param name=\"animationatStart\" value=\"true\">
<param name=\"transparentatStart\" value=\"true\">
<param name='autoStart' value=\"false\">
<param name=\"showControls\" value=\"true\">
<param name=\"Volume\" value=\"-450\">
<embed type=\"application/x-mplayer2\" pluginspage=\"http://www.microsoft.com/Windows/MediaPlayer/\" src=\"modules/$module_name/uploaded_videos/$uploaded_video_3\" name=\"MediaPlayer1\" width=\"640\" height=\"481\" autostart=1 showcontrols=1 volume=-450>
</object><BR><BR>";}
////////3 end/////////////////
//////////4 start/////////////
if ($text_4)
{
print "$text_4<BR><BR>";
}
if ($video_url_4)
{
print "$video_url_4<BR><BR>";}
if ($uploaded_video_4)
{
print "<object id=\"MediaPlayer1\" CLASSID=\"CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95\" codebase=\"http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701\"
standby=\"Loading Microsoft Windows® Media Player components...\" type=\"application/x-oleobject\" width=\"640\" height=\"481\">
<param name=\"fileName\" value=\"modules/$module_name/uploaded_videos/$uploaded_video_4\">
<param name=\"animationatStart\" value=\"true\">
<param name=\"transparentatStart\" value=\"true\">
<param name='autoStart' value=\"false\">
<param name=\"showControls\" value=\"true\">
<param name=\"Volume\" value=\"-450\">
<embed type=\"application/x-mplayer2\" pluginspage=\"http://www.microsoft.com/Windows/MediaPlayer/\" src=\"modules/$module_name/uploaded_videos/$uploaded_video_4\" name=\"MediaPlayer1\" width=\"640\" height=\"481\" autostart=1 showcontrols=1 volume=-450>
</object><BR><BR>";}
////////4 end/////////////////
//////////5 start/////////////
if ($text_5)
{
print "$text_5<BR><BR>";
}
if ($video_url_5)
{
print "$video_url_5<BR><BR>";}
if ($uploaded_video_5)
{
print "<object id=\"MediaPlayer1\" CLASSID=\"CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95\" codebase=\"http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=5,1,52,701\"
standby=\"Loading Microsoft Windows® Media Player components...\" type=\"application/x-oleobject\" width=\"640\" height=\"481\">
<param name=\"fileName\" value=\"modules/$module_name/uploaded_videos/$uploaded_video_5\">
<param name=\"animationatStart\" value=\"true\">
<param name=\"transparentatStart\" value=\"true\">
<param name='autoStart' value=\"false\">
<param name=\"showControls\" value=\"true\">
<param name=\"Volume\" value=\"-450\">
<embed type=\"application/x-mplayer2\" pluginspage=\"http://www.microsoft.com/Windows/MediaPlayer/\" src=\"modules/$module_name/uploaded_videos/$uploaded_video_5\" name=\"MediaPlayer1\" width=\"640\" height=\"481\" autostart=1 showcontrols=1 volume=-450>
</object>";}

 

this is why i need the file data to be put into SQL so i can pull it for the episode page

 

the admin part that puts the video info into the data base looks like this

function videos() {

global $prefix, $db, $sitename, $multilingual, $admin, $admin_file, $sitename, $module_name, $user_prefix;
include_once(NUKE_BASE_DIR.'header.php');

<form enctype=\"multipart/form-data\" method=\"post\" action=\"admin.php?op=videos&op=video_added\">
<table border=\"3\" width=\"100%\">
<tr>
<td class=\"background1\">

  <table border=\"3\" width=\"100%\">
  <tr>
  <td class=\"background6\">
Show's Title: </td><td class=\"background1\">
<select name=\"title\">";


$data = mysql_query("SELECT * FROM videos_series ORDER BY title ASC")  
or die(mysql_error()); 
while($info = mysql_fetch_array( $data )) 
{ 
$titleseries = $info['title'];

echo "
<option name=\"title\" value=\"$titleseries\">$titleseries</option>
";}

  echo "

</select>
  <tr>
  <td class=\"background6\">
video url title: </td><td class=\"background1\">
<select name=\"url_title\">";

$data = mysql_query("SELECT * FROM videos_series ORDER BY url_title ASC")  
or die(mysql_error()); 
while($info = mysql_fetch_array( $data )) 
{ 
$url_title2 = $info['url_title'];

echo "
<option name=\"url_title\" value=\"$url_title2\">$url_title2</option>
";}

  echo "
</select>
  </td>
  </tr>

  </td>
  </tr>

  <tr>
  <td class=\"background6\">
Episode #: </td><td class=\"background1\"><input type=\"text\" name=\"ep\">
  </td>
  </tr>

  <tr>
  <td class=\"background6\">
Put Video text here shows up at the top of Video 1: </td><td class=\"background1\"><input type=\"text\" name=\"text\">
  </td>
  </tr>

  <tr>
  <td class=\"background6\">
Video Embed #1: </td><td class=\"background1\"><input type=\"text\" name=\"video_url\">
  </td>
  </tr>

  <tr>
  <td class=\"background6\">
Uploaded Video Embed #1: </td><td class=\"background1\"><input class=\"video_select\" type=\"file\" name=\"file[]\" id=\"uploaded_video[]\">
  </td>
  </tr>

  <tr>
  <td class=\"background6\">
Put Video text here shows up at the top of Video 2: </td><td class=\"background1\"><input type=\"text\" name=\"text_2\">
  </td>
  </tr>

  <tr>
  <td class=\"background6\">
Video Embed #2: </td><td class=\"background1\"><input type=\"text\" name=\"video_url_2\">
  </td>
  </tr>

  <tr>
  <td class=\"background6\">
Uploaded Video Embed #2: </td><td class=\"background1\"><input class=\"video_select\" type=\"file\" name=\"file[]\" id=\"uploaded_video[]\">
  </td>
  </tr>

  <tr>
  <td class=\"background6\">
Put Video text here shows up at the top of Video 3: </td><td class=\"background1\"><input type=\"text\" name=\"text_3\">
  </td>
  </tr>

  <tr>
  <td class=\"background6\">
Video Embed #3: </td><td class=\"background1\"><input type=\"text\" name=\"video_url_3\">
  </td>
  </tr>

  <tr>
  <td class=\"background6\">
Uploaded Video Embed #3: </td><td class=\"background1\"><input class=\"video_select\" type=\"file\" name=\"file[]\" id=\"uploaded_video[]\">
  </td>
  </tr>

  <tr>
  <td class=\"background6\">
Put Video text here shows up at the top of Video 4: </td><td class=\"background1\"><input type=\"text\" name=\"text_4\">
  </td>
  </tr>

  <tr>
  <td class=\"background6\">
Video Embed #4: </td><td class=\"background1\"><input type=\"text\" name=\"video_url_4\">
  </td>
  </tr>

  <tr>
  <td class=\"background6\">
Uploaded Video Embed #4 : </td><td class=\"background1\"><input class=\"video_select\" type=\"file\" name=\"file[]\" id=\"uploaded_video[]\">
  </td>
  </tr>

  <tr>
  <td class=\"background6\">
Put Video text here shows up at the top of Video 5: </td><td class=\"background1\"><input type=\"text\" name=\"text_5\">
  </td>
  </tr>

  <tr>
  <td class=\"background6\">
Video Embed #5: </td><td class=\"background1\"><input type=\"text\" name=\"video_url_5\">
  </td>
  </tr>

  <tr>
  <td class=\"background6\">
Uploaded Video Embed #5: </td><td class=\"background1\"><input class=\"video_select\" type=\"file\" name=\"file[]\" id=\"uploaded_video[]\">
  </td>
  </tr>


  </table>
  <input type=\"Submit\">
  </form>
  </td>
  </tr>
  </table>

";


function video_added() {
global $prefix, $db, $admin_file, $module_name;
    include_once(NUKE_BASE_DIR.'header.php');
    OpenTable();

echo "<center><BR><BR>"
    
    ."[ <a href=\"admin.php?op=videos\">"._RBACK."</a> ] </center>";

$timestamp = time();;
$destpath = "upload/";
$target = "$target$the_file";

while(list($key,$value) = @each($_FILES["file"]["name"])) {
if(!empty($value)){
if ($_FILES["file"]["error"][$key] > 0) {
echo "Error: " . $_FILES["file"]["error"][$key] . "<br/>" ;
}
else {
//take this off to remove the file name
$file_name = $timestamp.$_FILES['file']['name'];

$source = $_FILES["file"]["tmp_name"][$key] ;
$filename = $_FILES["file"]["name"][$key];
$filename = strtolower($filename);
$filename = "$timestamp$filename";
move_uploaded_file($source, $destpath . $filename) ;
$final_file_location = "$destpath$filename";
echo "<center>Uploaded to: $final_file_location<br/></center>";
//just remove the image source code below if not for images
echo "<center><h2><a href=\"$final_file_location\"target=\"_blank\"><img src=\"$final_file_location\" border=\"0\"></a></h2><center>";



}
}
}
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) {
echo "The file has been uploaded as $filename";
} else {
echo "<BR>Upload your file.";
}


$ep=$_POST['ep'];
$text=$_POST['text'];
$video_url=$_POST['video_url'];

$text_2=$_POST['text_2'];
$video_url_2=$_POST['video_url_2'];

$text_3=$_POST['text_3'];
$video_url_3=$_POST['video_url_3'];

$text_4=$_POST['text_4'];
$video_url_4=$_POST['video_url_4'];

$text_5=$_POST['text_5'];
$video_url_5=$_POST['video_url_5'];

$url_title=$_POST['url_title'];
$title=$_POST['title'];


$query = "INSERT INTO videos VALUES ('','','$title','$ep','$text','','','','$video_url','$uploaded_video','$text_2','$video_url_2','$uploaded_video_2','$text_3','$video_url_3','$uploaded_video_3','$text_4','$video_url_4','$uploaded_video_4','$text_5','$video_url_5','$uploaded_video_5','$url_title','','')";
mysql_query($query) or die("A MySQL error has occurred.<br />Your Query: " . $query . "<br /> Error: (" . mysql_errno() . ") " . mysql_error());



echo "<center><BR><BR>"
    
    ."[ <a href=\"admin.php?op=videos\">"._RBACK."</a> ] </center>";

    CloseTable();
    include_once(NUKE_BASE_DIR.'footer.php');
}

 

its just a for form to full in the blinks in the database

bc only admins can add anything is why im not worry to much about the file types/size but i would like to add that lol

 

Link to comment
Share on other sites

Without me writing your entire code for you, I'll tell some hints that maybe will help you along.

 

you have for sql

"title , upload_1, upload_2, upload_3, upload_4, upload_5"

 

if added a text input alongside your file upload in the form and label it description, add this line in your while loop and after value check

$description = $_POST["description"][$key];
$escaped_description = htmlentities($description, ENT_NOQUOTES);

then use this in your form

File: <input type="file" name="file[]"/> Description:<input size="80"type="text" name="description[]" style="color: #FFFFFF; font-family: Verdana; font-weight: bold; font-size: 12px; background-color: #000000;" size="15" value=""><br/>

 

So can make a sql insert something like this:

 

<?php
//these are just some random type examples of renaming to prevent bad syntax errors into mysql
$sql_title = $info['title'];
$sql_upload = $_FILE['name']['key'];
$final_file_location = "$destpath$filename";

/*mysql connection login info change these values to your own*/
        $con_upload = mysql_connect("localhost","username","password");
        if (!$con_upload) {
            die('Could not connect: ' . mysql_error());
        }
        /*connect to database - change databasename to own*/
        mysql_select_db("databasename", $con_upload);
        mysql_query('SET NAMES utf8');
//this line fir whatever values your database has
mysql_query("INSERT INTO files_data (title, description, file_location)
//this line can be any variable and follows same positions as above
VALUES ('$sql_title', '$escaped_description', '$final_file_location')");
//always close the connection
mysql_close($con_upload);
?>

 

Here is a sql statement to create the table and fields

 

CREATE TABLE `files_data` (
  `id` int(11) NOT NULL auto_increment,
  `title` varchar(255) default NULL,
  `description` text,
  `file_location` varchar(255) default NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;

-- 
-- Dumping data for table `files_data`
-- 

INSERT INTO `files_data` VALUES (1, 'Title', 'First Description.', 'files/filenumber1');
INSERT INTO `files_data` VALUES (2, 'Title2', 'Second Description', 'files/filenumber2');

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • 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.