NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page upload script

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

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 05-18-2005, 08:59 PM THREAD STARTER               #1 (permalink)
NamePros Regular
 
benc811's Avatar
Join Date: Oct 2004
Location: W. Hartford, CT
Posts: 361
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']))
????: NamePros.com http://www.namepros.com/programming/91299-upload-script.html
              {
                     echo 
"Error: Please select a file to upload!. <br>»<a href=\"$_SERVER[PHP_SELF]\">back</a>";
????: NamePros.com http://www.namepros.com/showthread.php?t=91299
                     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-19-2005, 12:46 AM   #2 (permalink)
NamePros Regular
Join Date: Jan 2005
Posts: 258
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, 02:54 AM   #3 (permalink)
Join Date: Dec 2004
Posts: 1,060
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 allsnareklutz is a name known to allsnareklutz is a name known to all
 



Is this the ZachWhite uploader script?
__________________
For sale: forexstochastics.com
snareklutz is offline  
Old 05-21-2005, 07:08 AM   #4 (permalink)
NamePros Member
Join Date: Nov 2003
Location: Ontario, Canada
Posts: 127
eagle12 will become famous soon enougheagle12 will become famous soon enough
 



You could use a radio group. and just replace:

$upload_dir = "pictures/";

with:

$upload_dir = $_POST['radiogroup']."/";
eagle12 is offline  
Old 05-21-2005, 11:59 AM   #5 (permalink)
Account Closed
Join Date: May 2005
Location: Your websites source code
Posts: 151
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


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 10:48 AM
Domain Rating Script for Sale : $200.00 - only 10 scripts will be sold fonzerelli_79 Scripts For Sale 3 08-31-2003 09:41 AM

Liquid Web Smart Servers  
All times are GMT -7. The time now is 08:49 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger