vainsoft
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: CODE <? //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>
Any help with this will be grateful.
Comment/Reply (w/o sign-up)
OpaQue
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> <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> Save that as upload.Html Then for the php add CODE <? //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! ?> and save that as upload.Php (please note casing is important) 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
Comment/Reply (w/o sign-up)
(G)Thomas Norberg
Nov 10 2009, 09:58 PM
THIS ROCKS FINALLY!!!!!
Php Ftp Upload Form
I finally was able to find something that would work for to upload files for all my users...Eventually I will have my plugin do all this work for me. So thank you so much for making this known, this rocks...
-reply by Thomas Norberg
Comment/Reply (w/o sign-up)
Similar Topics
Keywords : php, ftp, upload, form, adding, user, directory, php, upload, form,
- Securing Upload Directory
proper way to do it? (6)
Php Counting Row By Specific User And Limit!
(6) i need to count the results sent by users ,i need a code to start counting results and find me
results from the same user ,i want to be able to limit results by user ,i want to limit the user to
maximum 4 rows in a run if it reaches 5 rows the result number 5 will be deleted or something !
this is my example code fo geting the results: SQL select * from my table where
username = $username and bidprice = $bid_price order by bid_price desc like this situation
is good: 4 result from the same user then user 2 is between ,the result 5 from user 1 ,use....
Unexpected T_string In User.php [resolved]
(5) Ok so i'm working on a site for my chruch, and i seem to be having a little bit of trouble with
the user.php file i keep getting the following error: CODE Parse error: syntax error,
unexpected T_STRING in /home/darkzone/public_html/test/user.php on line 195 and i was wondering
if some one could help me with the script. session_start(); ob_start(); //Include the
configurations include('config.php'); //Define a few variables $x = $_GET ; $u = $_GET
; class register { function displayform($title) { echo(' '.$title.' Use....
Image Upload
?!? (11) I need the image upload script which automatically resized the image by specified size and store it
in the specified folder.....
How To Display Images Of A Directory
(5) I am trying to do a simple thing. I want to display all the images of a directory on a single page
with the checkbox next to each image, so that i can select multi images and i can delete selected
images. Following few lines of code display the images of a directory.. i need help to put the
check boxes with each image. and I dont understand how can i select multi images with check box and
then delete them. I hope someone can help. thanks. CODE $path = "./"; $dir_handle =
@opendir($path) or die("Unable to open folder"); while (false !== ($file = readdir($dir_han....
[mysql]get Id Of Loged In User?
(7) how to get the id number of the loged in user? my db is id. username. password. i have tryed a
few things.. but i never seem to get it right /ohmy.gif" style="vertical-align:middle" emoid=":o"
border="0" alt="ohmy.gif" />....
Adding String To Integer?
(1) Create a PHP program with the following requirements Create a program that does the following:
creates a variable called “test” (remember the dollar sign) stores the number 35 to
test and prints the result adds 10.0000 to test and prints the result subtracts 5.123123 from
test and prints it out stores the character string “happy to be here” to test and
prints adds 10.0000 to the variable test (try to guess what will happen) whats the solution to
this problem? any help would be appreciated.....
Compare 2 List Of User Ids From Different Tables
(1) Hi all. I am trying to make a list out of 2 list. The first list is a complete list of users id
from users table (List A) The Second list is of users id from another table (List /cool.gif"
style="vertical-align:middle" emoid="B)" border="0" alt="cool.gif" /> I want to subtrack the user
ids in List B from List A and make List C. Thanks in advance for any help /smile.gif"
style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> Update: I looked up a old
sql book i had and found some query examples. I tried the EXCEPT statement in mysql but it dont wor....
Multiple Drop Down Lists ?
Multiple drop down lists to take user to new page (4) Hi everyone I was wondering if anyone could help. I want to create a page with multiple drop down
lists and depending what the user selects decides the page they will be taken to. Sorry i havent
explained this too well. Here is an example of what i want (link below) the user is also emailed a
copy http://www.dermalogica.com/SpeedMappingOnl...US®ion=B I have searched the web and come
close but nothing does it right I would be extremely greatful if anyone could help! Thanks ....
File Upload
File upload (1) I need to add a facility on my customer's website so his clients can send him jobs, typically
5mb - 50mb. I've looked around the web and researched this, and tried a few tests (failed), but
my brain's beginning to hurt. Could someone please tell me the best way to go about this,
please. The site is done in Flash, but I'm sure a link to an html page would be ok if necessary.....
Batch Upload Script
In need of batch upload script (1) I'm in the process of making a photo gallery script. I need ideas on how to make a batch upload
script. I want the user to be able to upload files to a folder via FTP and then go to the admin
section of the gallery and add the previously uploaded photos to the MySQL database. I guess what I
need it to do is find all the files in a specific folder and see if they are already in the
database, if they aren't in the database - add them. Any help would be appreciated. I figured
trap17 would be a good place to get help with this /wink.gif" style="vertical-align:middle....
Unofficial Trap17 Hosted Members Directory
(13) This is the Trap17 edition of the Hosted Members Directory. A script initially written by me for the
Astahost forums. The script has gone through many a changes and is currently in version 4 which
includes the following features:- > Listing of hosted members. > Listing of the websites of the
hosted members. > Validation of the websites (whether the site is suspended, working or not not
working, etc) > Save/Load result to/from database. > Multithreaded for faster operation. > Status
messages, images and progress bar to keep you informed of the process. Link to the Scrip....
Reading Files From Directory To Array, And Using $_get To Get Them
Simple way to manage lot's of files (2) Some user posted a similar problem i had when i tried to figure out how to update content on my
website in less work as possible. This is just part of the "big" plan i have for my site but it can
be helpfull to you guys if you like FlatFile. I hope that mod's don't mind me posting the
same code here and on their forums, couse if they do i'll delete it from their forums
/biggrin.gif" style="vertical-align:middle" emoid=":D" border="0" alt="biggrin.gif" /> So
here's the situation. Let's say you have a folder called 'myfilesdirectory' on your
s....
Directing To A User To Specific Page First Time Only
(3) I make a signup page. I want that when someone signups and login for first time..then he is directed
to the page X automatically. but after that it is redirected to Page Y always... Its pretty simple
thing to do but im not understanding how i can make the script to identify that a person has logged
in for first time ... anyhelp would be so welcome. Thanks.....
Help Needed With Directory/file Listing Code Infinite Loop
Made an infinite loop but why is this so? (5) Hi all ive got a small and simple (for the moment atleast /unsure.gif"
style="vertical-align:middle" emoid=":unsure:" border="0" alt="unsure.gif" /> )file and directory
listing script in php as follows CODE $dir = "."; $num = 0; $file = scandir($dir); while($file
= scandir($dir)){ echo $file ; echo " "; $num = $num + 1; }; the concept is
simple enough, the directory to start with is the current one, so scan this directory and while we
have a result do a loop to echo the file/directories found, incriment the array number by one so we
get the....
Php Codes: Adding Clothing, Ion Laser Guns And Shooting Projectile Cannons
(3) Ok here is a set of codes that is on another forum website. It is really neat becuase you can have
cursors and other objects on your webpage that can shot projectiles. Also you can add some other
cool graphics. Go to the link below. php coding ....
Display Random File In A Directory
how to display a random file from a set directory. (9) hi, could someone please help me with this? I have some files in a directory and i want to know how
i can randomly display link/s to one or more of the files in my directory for download. But it must
not at any time display index.php which is also in the directory with the downloads. Thanks in
advance for any help given /unsure.gif" style="vertical-align:middle" emoid=":unsure:" border="0"
alt="unsure.gif" />....
Changin My Phpnuke Directory...please Help
(13) ok i wus fantastico to install my nuke...it asked me to give it a name for its directory so ive put
down "nuke" so to get to my site ud have to go to www.boaw.trap17.com/"nuke" but now i want to
change nuke into something else more related to the site...i was wondering if any1 can tell me the
best way to do that...thanks....
Displaying Files Of A Directory
(2) I want to display the contents of a directory.. i have the following code.. It gives the output in
one column only... like file1 file2 file3 file4 . . . . . Since there are lot of files so this
column gets very long..i want to display the x number of files in each column.. like if there are 22
files.. then file 1 file 11 file 21 file 2 . file 22 file 3 .. . . . file 10
file 20 This was just an example..I know it can be done by using but i dont know how to do it
with loop. Please help me. QUOTE $dir = './'; $handle = opendir($....
Wappyftp V1.00
upload to server via ftp from your mobile phone :-) (8) wappyFTP v1.00 by wappy --- site: http://cult.trap17.com mail: admin@cult.trap17.com --- -Welcome
to wappyFTP, with this wap script your users can upload files directly to their server via FTP from
a mobile phone! --- -Its extremley easy to install, open index.php and put the name of your site
instead of YOURSITE.COM -Upload the folder wappyFTP_v1.00 to the root directory of your web server
-Link to it like wappyFTP_v1.00/index.php -Its all done ENJOY --- YOU MAY DISTRIBUTE AND/OR EDIT
THIS SCRIPT BUT DO NOT REMOVE THE AUTHORS NAME! --- ©2006-2007 wappyCULT /tongue.g....
Script That Tracks The User Status
how can I track on or offline users? (4) long explaination: hey, I'm building a user profile site right now. And, I kinda know how to
make a online/offline detector, but not totally sure. I know I can make a mysql database to track
them, but how does it entrer the information? I could easily put in a field where when they login it
sets them to online, but if they don't sign out, and just exit the browser, how can I tell.
short: I want someone to tell me how to make a online/offline status detector, like they have here
on trap17. I'd be thrilled if you can post to this, thanks, arcticsnpr....
How To List Files In A Directory + Subdirectory And Then Use Them.
(8) So lets say i have folders called friends and work in a folder called pics. how would i make a
function that lists the files in those folderscalled images kinda like this: CODE
$directory = "./" function listfiles($directory) { //here should go the script to list the files in
those directories. so that i can continue to work with them. like for example if there were images
it would list all the images and i could write a script to make a thumb of them and then save it
into a thumb folder(not asking for all of that). but how would i make it list it. // basic....
Directory Files Displaying
(5) I have many files in a directory..I want to create a page , like A B C D E F ..... when some one
click on A , it should display all the files starting from letter A , and when clicks on B , it
should show all the files in that directory starting from B , and so on... I have no idea how to
display the files of the directory iin that way. Kindly assist me......
How To Sort Files Of A Directory using Php
(13) The following code displays the files of folder...but they are displaced by the order of adding... i
want to sord the files / folders alphabetically and sord by accending order and by decending
order.. can some one help me. $path = ""; $dir_handle = @opendir($path) or die("Unable to open
$path"); echo "Directory Listing of $path "; while($file = readdir($dir_handle)) {
if(is_dir($file)) { continue; } else if($file != '.' && $file !=
'..') { echo " $file "; } } //closing the directory
closedir($dir....
Password Strength / User Availablity Scripts ?
(2) many of u guys would already have noticed that now a days , on most of the websites , when some one
sign in...as he puts his desired username in the textbox , the page shows that it is not available
or it is available...without pushing any button etc.. and the second thing , when some one writes
the password , on the same screen , it shows that password is weak or password is strong... i think
it is done with php ... can some one give me a link to any page where i can access these scripts ?
or some one can help me regarding this ?? Thanks for helping always.....
Adding One Day To Date
i'd like to add one day to date (9) I would like to add one day to date.Doesn't any one have a simple code that I can have. or mabe
a link. date("Y-m-d H:i:s") + (1800 * 24);//this doesnt work ;/ but i need to have 24 hours after
date for a check. Thanks for taking the time i hope some one can help me out. Dont warry about it
if you dont have some thing already made. ....
Login / Authetication System Using Database
adding information (4) Is there any way to make such database where I can write like name and passwords.. Then make an
login box, and when somebody trys to acces the login he needs to write the name and password.. Then
it is verifyed if is there such name and password and if it is then acces the page.. I think there
is posible something like that with MySQL (db).. but can anybody say me a script or way to make
something like that? Alredy thanks......
Adding Users To Databases Using Phpmyadmin
(3) I am running my own apache server with PHP and MySQL, with phpMyAdmin on my own computer, to test
things locally. I know how to create databases and how to create users, but how can I add a user to
a database?....
Upload Pics With Php?
(6) Can anyone help me out again? Thanks. I need a code that has a basic form that allows you to
browse for an image file and when the submit button is clicked, that image gets uploaded to a folder
in my site (e.g. images/*.jpg)....
Getting List Of Directories And Files Using Php
PHP Function for Directory and File List (6) is there a php function that lists the content of some folder.... example: /New folder new.txt
left.gif download.zip dc.exe ....so is there..? /rolleyes.gif' border='0'
style='vertical-align:middle' alt='rolleyes.gif' /> ....
Looking for php, ftp, upload, form, adding, user, directory, php, upload, form,
|
Searching Video's for php, ftp, upload, form, adding, user, directory, php, upload, form,
See Also,
|
advertisement
|
|