[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.


Closed Thread
 
LinkBack Thread Tools
Old 05-18-2005, 07:59 PM   #1 (permalink)
NamePros Regular
 
Join Date: Oct 2004
Posts: 317
5.91 NP$ (Donate)

benc811 is a jewel in the roughbenc811 is a jewel in the roughbenc811 is a jewel in the rough


upload script

I have this upload script but it only stores the files in a set directory how can i make this dynamic would i just make the directory a variable and add some radio buttons with the name of the directorys? heres the code.

PHP Code:
<html>
<head>
<title>Upload music</title>
<LINK href="style.css" type=text/css rel=StyleSheet>
</head>
<body text=#ffffff bgColor=#4e4e4e>
<FONT size=2><STRONG>
<?php
//**********************************************************************//
//  $_FILES['filetoupload']  is the value of                            //
// file field from the form. <input type="file" name="filetoupload">    //
//**********************************************************************//
// this is the upload dir where files will go.
//Don't remove the /
//Chmod it (777)
$upload_dir = "pictures/";   //change to whatever you want.

             //51200 bytes = 50KB
$size_bytes = 512000; //File Size in bytes (change this value to fit your need)

$extlimit = "yes"; //Do you want to limit the extensions of files uploaded (yes/no)
$limitedext = array(".mp3"); //Extensions you want files uploaded limited to. also you can use:  //array(".gif",".jpg",".jpeg",".png",".txt",".nfo",".doc",".rtf",".htm",".dmg",".zip",".rar",".gz",".exe");

          //check if the directory exists or not.
          
if (!is_dir("$upload_dir")) {
         die (
"The directory <b>($upload_dir)</b> doesn't exist");
          }
          
//check if the directory is writable.
          
if (!is_writeable("$upload_dir")){
             die (
"The directory <b>($upload_dir)</b> is NOT writable, Please CHMOD (777)");
          }
          
  if(
$uploadform) // if you clicked the (Upload File) button. "If you submitted the form" then upload the file.
  
{//begin of if($uploadform).


              //check if no file selected.
              
if (!is_uploaded_file($_FILES['filetoupload']['tmp_name']))
              {
                     echo
"Error: Please select a file to upload!. <br>»<a href=\"$_SERVER[PHP_SELF]\">back</a>";
                     exit();
//exit the script and don't do anything else.
              
}

              
//Get the Size of the File
              
$size = $_FILES['filetoupload']['size'];
              
//Make sure that file size is correct
              
if ($size > $size_bytes)
              {
                    
$kb = $size_bytes / 1024;
                    echo
"File Too Large. File must be <b>$kb</b> KB. <br>»<a href=\"$_SERVER[PHP_SELF]\">back</a>";
                    exit();
              }

              
//check file extension
              
$ext = strrchr($_FILES['filetoupload'][name],'.');
              if ((
$extlimit == "yes") && (!in_array($ext,$limitedext))) {
                    echo(
"We do not support that kind of file please try again ");
                    exit();
              }

              
// $filename will hold the value of the file name submetted from the form.
              
$filename =  $_FILES['filetoupload']['name'];
              
// Check if file is Already EXISTS.
              
if(file_exists($upload_dir.$filename)){
                    echo
"Oops! The file named <b>$filename </b>already exists. <br>»<a href=\"$_SERVER[PHP_SELF]\">back</a>";
                    exit();
              }

              
//Move the File to the Directory of your choice
              //move_uploaded_file('filename','destination') Moves afile to a new location.
              
if (move_uploaded_file($_FILES['filetoupload']['tmp_name'],$upload_dir.$filename)) {

                  
//tell the user that the file has been uploaded and make him alink.
                  
echo "File (<a href=$upload_dir$filename>$filename</a>) uploaded! <br>»<a href=\"$_SERVER[PHP_SELF]\">back</a>";
                  exit();

              }
                  
// print error if there was a problem moving file.
                  
else
              {
                  
//Print error msg.
                  
echo "There was a problem moving your file. Try again. <br>»<a href=\"$_SERVER[PHP_SELF]\">back</a>";
                  exit();
              }



  }
//end of if($uploadform).

#---------------------------------------------------------------------------------#
// If the form has not been submitted, display it!
else
  {
//begin of else
  
      
?>
      <br>
      <h3>Only MP3 tracks are accepted.</h3>
      <i></i>

        <b>
          <?
        
// print the file extensions
        
for($i=0;$i<count($limitedext);$i++)
    {
        if ((
$i<>count($limitedext)-1))$commas=", ";else $commas="";
        list(
$key,$value)=each($limitedext);
        echo
$value.$commas;
    }
    
?>
    </b>
    
      <br>
      <i>- Max File Size</i> = <b><?echo $size_bytes / 1024; ?> KB </b>
      <br>
      <form method="post" enctype="multipart/form-data" action="<?php echo $PHP_SELF ?>">
      <br>
      <input type="file" name="filetoupload"><br>
      <input type="hidden" name="MAX_FILE_SIZE" value="<?echo $size_bytes; ?>">
      <br>
      <input type="Submit" name="uploadform" value="Upload File">
      </form>

      <?
  
  
}//end of else

/*______________________________________________________________________________*/
//   Here is the most interesting part.
//    it views the directory contents.....i'll disscuss next version. (ver 2.0)
?>
</table>
<p align=center>
<br>ATW is not responsible for any stolen music!
</p>
</STRONG></FONT>
</body>
</html>
__________________
benc811 is online now  
Old 05-18-2005, 11:46 PM   #2 (permalink)
NamePros Regular
 
Join Date: Jan 2005
Posts: 258
2.00 NP$ (Donate)

suppau is an unknown quantity at this point


Neat upload script, however like you've said, It's a predefined folder. Rather than modifying the script, why not try this site : http://www.blueshoes.org/en/applications/filemanager
suppau is offline  
Old 05-21-2005, 01:54 AM   #3 (permalink)
 
Join Date: Dec 2004
Posts: 1,055
142.50 NP$ (Donate)

snareklutz is a name known to allsnareklutz is a name known to allsnareklutz is a name known to allsnareklutz is a name known to allsnareklutz is a name known to allsnareklutz is a name known to all


Is this the ZachWhite uploader script?
__________________
My Afternic Names - no more sedo for me!!!
snareklutz is offline  
Old 05-21-2005, 06:08 AM   #4 (permalink)
NamePros Member
 
Join Date: Nov 2003
Location: Ontario, Canada
Posts: 91
80.80 NP$ (Donate)

eagle12 is on a distinguished road


You could use a radio group. and just replace:

$upload_dir = "pictures/";

with:

$upload_dir = $_POST['radiogroup']."/";
eagle12 is offline  
Old 05-21-2005, 10:59 AM   #5 (permalink)
Account Closed
 
Join Date: May 2005
Location: Your websites source code
Posts: 151
138.41 NP$ (Donate)

leprechaun13 is on a distinguished road


Try the "Genesis" control panel this is good for a standard upload script
leprechaun13 is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
60.000 Templates, scripts, fonts, banners etc. $9.95 atkims Web Development Wanted 19 11-16-2004 09:48 AM
Domain Rating Script for Sale : $200.00 - only 10 scripts will be sold fonzerelli_79 Scripts For Sale 3 08-31-2003 08:41 AM

Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 12:37 PM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85