|
|
|
|
![]() ![]() |
![]() Group: Members
Posts: 1 Joined: 9-February 08 Member No.: 57,609 |
Post
#1
Feb 9 2008, 05:06 PM
Alright I am trying to have a PHP FTP Upload Form that allows the user to create the directory folder for where they want to upload there files to. example: Main Directory: vainsoft.com There directory: vainsoft.com/modeling or vainsoft.com/photography But I dont want them to be able to upload things into the main directory, only sub-directories, is that possible with this coding that I have: [codebox] <? //uses $_FILES[] global array //see manual for older PHP version info //This function will be used to get the extension from the filename function get_extension($file,$length=-1){ $p = strrpos($file,"."); $p++; if($length!=-1){ $ext = substr($file,$p,$length); } if($length==-1){ $ext = substr($file,$p); } $ext = strtolower($ext); return $ext; } //Not good practice, but here anyway //change to suit your needs //also some have to be set in the ini //for this to correctly work //2meg max ini_set("upload_max_filesize","100M"); //turn on file uploads ini_set("file_uploads","1"); //set your temp dir ini_set("upload_tmp_dir","/tmp"); //set post size large enough to accomidate //3 100meg files and some overhead ini_set("post_max_size","180M"); ?> <html> <head> <title>VainSoft - Upload Form</title> </head> <body> <? //check to see if we have submited yet if($_POST["submit"]!="submit"){ //not yet so lets make the form ?> <p>Upload Images here, 10 images at a time, hit back after upload to upload more. (100M MAX)</p> <p> <form name="fileup" method="post" enctype="multipart/form-data" action="<? echo $PHP_SELF; ?>"> <input type="file" name="userfiles[]"><br> <input type="file" name="userfiles[]"><br> <input type="file" name="userfiles[]"><br> <input type="file" name="userfiles[]"><br> <input type="file" name="userfiles[]"><br> <input type="file" name="userfiles[]"><br> <input type="file" name="userfiles[]"><br> <input type="file" name="userfiles[]"><br> <input type="file" name="userfiles[]"><br> <input type="file" name="userfiles[]"><br> <br> <!-- change below to your max --> <input type="hidden" name="MAX_FILE_SIZE" value="1000000000"> <input type="submit" value="submit" name="submit"> </form> </p> <? } //see if we have submited and that the files array has been set if(($_POST["submit"]=="submit")&&(is_array($_FILES['userfiles']))){ $ftp_user_name="******"; //change to ftp username $ftp_user_pass="******"; //change to ftp password $ftp_server="******"; //change to ftp url $ftp_dump_dir="******"; //change to destination directory //go through all the files for($x=0;$x<count($_FILES['userfiles']['name']);$x++){ //now we do some file checking //check to see if file is there if($_FILES['userfiles']['name'][$x]!="none"){ //file has a name //check filesize if($_FILES['userfiles']['size'][$x]!=0){ //file is larger than 0 bytes //Check to see if it is uploaded if(is_uploaded_file($_FILES['userfiles']['tmp_name'][$x])){ //file has been uploaded! //let the user know their file has be uploaded echo "file ".$_FILES['userfiles']['name'][$x]." uploaded!<br>"; //conect to ftp server $conn_id = ftp_connect($ftp_server); // login with username and password $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); // check connection if ((!$conn_id) || (!$login_result)) { echo "FTP connection has failed!<br>"; echo "Attempted to connect to $ftp_server for user $ftp_user_name"; exit; } else { echo "Connected to $ftp_server! <br>"; //set PASV mode if(!ftp_pasv($conn_id,TRUE)){ echo "Could not enter PASV mode!"; } //rename to file#_date.ext $filename = $_FILES['userfiles']['name'][$x]; //$filename.= ".".get_extension($_FILES['userfiles']['name'][$x],3); //change directory if (@ftp_chdir($conn_id, $ftp_dump_dir)) { //maybe you want to make sure we are in the correct directory echo "Current directory is now : ", ftp_pwd($conn_id), "\n"; } else { //you want to know if it didn't work echo "Couldn't change directory\n"; } //upload the file and let the user know what happened if(ftp_put($conn_id,$filename,$_FILES['userfiles']['tmp_name'][$x],FTP_BINARY)){ echo "File ".$_FILES['userfiles']['name'][$x]." was sent successfully<br>"; echo "File was named ".$filename."<br>"; }else{ echo "There was a problem sending file ".$_FILES['userfiles']['name'][$x]."<br>";; } } // close the FTP stream ftp_close($conn_id); } else echo"File was not uploaded!<br>"; } } echo "<br>"; }//end for loop } //That's all folks! ?> </body> </html> [/codebox] Any help with this will be grateful. |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Admin
Posts: 1,624 Joined: 11-June 04 From: Somewhere in Time & Space. Member No.: 1 myCENT:NEGATIVE[-85.03] |
Post
#2
Aug 29 2008, 02:37 PM
I think I can help here but I'm not sure first take out all your html. CODE <html> Save that as upload.Html<head> <title>VainSoft - Upload Form</title> </head> <body> <p>Upload Images here, 10 images at a time, hit back after upload to upload more. (100M MAX)</p> <p> <form name="fileup" method="post" enctype="multipart/form-data" action="upload.Php"> <input type="file" name="userfiles[]"><br> <input type="file" name="userfiles[]"><br> <input type="file" name="userfiles[]"><br> <input type="file" name="userfiles[]"><br> <input type="file" name="userfiles[]"><br> <input type="file" name="userfiles[]"><br> <input type="file" name="userfiles[]"><br> <input type="file" name="userfiles[]"><br> <input type="file" name="userfiles[]"><br> <input type="file" name="userfiles[]"><br> <br> <!-- change below to your max --> <input type="hidden" name="MAX_FILE_SIZE" value="1000000000"> <input type="submit" value="submit" name="submit"> </form> Then for the php add CODE <? and save that as upload.Php (please note casing is important)//uses $_FILES[] global array //see manual for older PHP version info //This function will be used to get the extension from the filename Function get_extension($file,$length=-1){ $p = strrpos($file,"."); $p++; If($length!=-1){ $ext = substr($file,$p,$length); } If($length==-1){ $ext = substr($file,$p); } $ext = strtolower($ext); Return $ext; } //Not good practice, but here anyway //change to suit your needs //also some have to be set in the ini //for this to correctly work //2meg max Ini_set("upload_max_filesize","100M"); //turn on file uploads Ini_set("file_uploads","1"); //set your temp dir Ini_set("upload_tmp_dir","/tmp"); //set post size large enough to accomidate //3 100meg files and some overhead Ini_set("post_max_size","180M"); ?> </p> <? //check to see if we have submited yet If($_POST["submit"]!="submit"){ //not yet so lets make the form ?> <? } //see if we have submited and that the files array has been set If(($_POST["submit"]=="submit")&&(is_array($_FILES['userfiles']))){ $ftp_user_name="*****"; //change to ftp username $ftp_user_pass="*****"; //change to ftp password $ftp_server="******"; //change to ftp url $ftp_dump_dir="/files"; //change to destination directory //go through all the files For($x=0;$x<count($_FILES['userfiles']['name']);$x++){ //now we do some file checking //check to see if file is there If($_FILES['userfiles']['name'][$x]!="none"){ //file has a name //check filesize If($_FILES['userfiles']['size'][$x]!=0){ //file is larger than 0 bytes //Check to see if it is uploaded If(is_uploaded_file($_FILES['userfiles']['tmp_name'][$x])){ //file has been uploaded! //let the user know their file has be uploaded Echo "file ".$_FILES['userfiles']['name'][$x]." uploaded!<br>"; //conect to ftp server $conn_id = ftp_connect($ftp_server); // login with username and password $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); // check connection If ((!$conn_id) || (!$login_result)) { Echo "FTP connection has failed!<br>"; Echo "Attempted to connect to $ftp_server for user $ftp_user_name"; Exit; } else { Echo "Connected to $ftp_server! <br>"; //set PASV mode If(!ftp_pasv($conn_id,TRUE)){ Echo "Could not enter PASV mode!"; } //rename to file#_date.Ext $filename = $_FILES['userfiles']['name'][$x]; //$filename.= ".".Get_extension($_FILES['userfiles']['name'][$x],3); //change directory If (@ftp_chdir($conn_id, $ftp_dump_dir)) { //maybe you want to make sure we are in the correct directory Echo "Current directory is now : ", ftp_pwd($conn_id), "\and"; } else { //you want to know if it didn't work Echo "Couldn't change directory\and"; } //upload the file and let the user know what happened If(ftp_put($conn_id,$filename,$_FILES['userfiles']['tmp_name'][$x],FTP_BINARY)){ Echo "File ".$_FILES['userfiles']['name'][$x]." was sent successfully<br>"; Echo "File was named ".$filename."<br>"; }else{ Echo "There was a problem sending file ".$_FILES['userfiles']['name'][$x]."<br>";; } } // close the FTP stream Ftp_close($conn_id); } Else echo"File was not uploaded!<br>"; } } Echo "<br>"; }//end for loop } //That's all folks! ?> No when you log in to your ftp make sure that you CHMOD the directory to 777, this should help, Connor -reply by Connor QUOTE Posted at Trap17 Feedback System
|
![]() ![]() |
Similar Topics
| Topic Title | Replies | Topic Starter | Views | Last Action | |||
|---|---|---|---|---|---|---|---|
![]() |
6 | LuciferStar | 11,417 | 7th November 2004 - 12:40 PM Last post by: eldeo |
|||
![]() |
4 | LuciferStar | 7,614 | 19th August 2004 - 01:39 AM Last post by: LuciferStar |
|||
![]() |
2 | FallenSage | 1,234 | 18th July 2006 - 05:28 AM Last post by: FallenSage |
|||
![]() |
7 | football123213 | 15,572 | 20th August 2004 - 12:25 AM Last post by: ill |
|||
![]() |
12 | -prodigy- | 12,320 | 22nd September 2004 - 04:34 AM Last post by: -prodigy- |
|||
![]() |
3 | guangdian | 4,943 | 20th August 2009 - 06:59 PM Last post by: iworld200 |
|||
![]() |
1 | hansley | 7,676 | 11th October 2004 - 03:54 AM Last post by: Trystim |
|||
![]() |
5 | odomike | 10,359 | 27th October 2004 - 02:29 AM Last post by: odomike |
|||
![]() |
6 | sargilla | 6,789 | 4th November 2004 - 02:54 PM Last post by: Lyon |
|||
![]() |
6 | wild20 | 1,402 | 8th June 2006 - 10:04 PM Last post by: wild20 |
|||
![]() |
4 | AlternativeNick | 814 | 10th June 2006 - 09:08 PM Last post by: farsiscript |
|||
![]() |
0 | twoq | 4,314 | 7th November 2004 - 06:19 AM Last post by: twoq |
|||
![]() |
4 | shyam | 3,610 | 14th November 2004 - 08:42 AM Last post by: googlue |
|||
![]() |
1 | Mike | 2,984 | 19th November 2004 - 05:52 AM Last post by: -prodigy- |
|||
![]() |
7 | cragllo | 5,533 | 14th December 2004 - 01:51 AM Last post by: khmerneed |
|||
|
Open Discussion | Time is now: 8th November 2009 - 11:44 AM |
Web Hosting Powered by ComputingHost.com.