/    Sign up×
Community /Pin to ProfileBookmark

need help with ftp uploading script

ok i have a connection script and everything and it works but now i need like a form like freewebs has that allows u to browse through your computers files and then when u select one and hit upload it enters the right information into the variable in the script and cuts it down to the short filename and then uploads it and i was wondering if anyone knows where i could find one or if someone could make one pls and ty

to post a comment
PHP

34 Comments(s)

Copy linkTweet thisAlerts:
@SheldonNov 23.2005 — you need a form with multi part entype, a <input type="file">

then the php sode you need to use your ftp connection scipt and [url=http://php/net/manual/en/function.move-uploaded-file.php]move_uploaded_file[/url]
Copy linkTweet thisAlerts:
@Heavy_MetalauthorNov 23.2005 — it says that that function doesn't exsist
Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYNov 23.2005 — because sheldon wrote php/net instead of php.net in the url

i don't even know how it is possible that it still find php.net

look: http://php/net => http://php.net
Copy linkTweet thisAlerts:
@SheldonNov 23.2005 — haha im a stupid barstard, um because it had

http://php.inspire.net.nz/manual/en/function.move-uploaded-file.php

and i took out teh inspire.et.nz and was ment to put php.net not php/net keyboard error not mine ???
Copy linkTweet thisAlerts:
@Heavy_MetalauthorNov 23.2005 — oooo ok thanks and that is wierd how it gets http://php.net out of http://php/net lol
Copy linkTweet thisAlerts:
@SheldonNov 23.2005 — I cant get that, i get cant find server
Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYNov 23.2005 — thats because it doesnt work in the southern hemisphere :p
Copy linkTweet thisAlerts:
@Heavy_MetalauthorNov 24.2005 — ok anyways i have the form and everything that lets the user browse for the file and everything and then it sends it to the upload page and now i need the script that would change it to the short file name and then uploads it and i cant seem to figure it out so could u help me pls
Copy linkTweet thisAlerts:
@SheldonNov 24.2005 — Post your code so far

[ php ] tags plaese
Copy linkTweet thisAlerts:
@Heavy_MetalauthorNov 24.2005 — [code=php]<html>
<body>

<?php
$file = 'somefile.txt';
$remote_file = 'readme.txt';
$ftp_user_name = 'myusername';
$ftp_user_pass = 'mypassword';
$ftp_server = 'ftp.bowhuntr.net';

// set up basic connection
$conn_id = ftp_connect($ftp_server);

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// upload a file
if (ftp_put($conn_id, $remote_file, $file, FTP_ASCII)) {
echo "successfully uploaded $filen";
} else {
echo "There was a problem while uploading $filen";
}

// close the connection
ftp_close($conn_id);
?>
</body>
</html>[/code]


there ya go
Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYNov 24.2005 — Does your PHP have ftp support enabled?
Copy linkTweet thisAlerts:
@bokehNov 24.2005 — Why are you doing this with ftp? Is there a reason that you can't use standard http uploads?
Copy linkTweet thisAlerts:
@Heavy_MetalauthorNov 24.2005 — to LiLcRaZyFuZzY: yes it does as far as i know, and to bokeh: i can and i do do it with the standerd uploads but my friend likes to upload images alot and im getting tired of him sending it to me and then me uploading it so im trying to build this so that he wont have to send it to me
Copy linkTweet thisAlerts:
@bokehNov 24.2005 — You could make an html upload page (non-ftp) page just for him, password protected.
Copy linkTweet thisAlerts:
@SheldonNov 25.2005 — [code=php]
// path to save file to
$UploadDir = 'images/uploads/';
$UploadFileName = $UploadDir . $_FILES['image']['name'];

if (move_uploaded_file($_FILES['image']['tmp_name'], $UploadFileName)) {

print 'Photo upladed';

}else{

print 'error';

}//end this upload form
[/code]
Copy linkTweet thisAlerts:
@Heavy_MetalauthorNov 25.2005 — ok but could you please integrate my previous code [code=php]<html>
<body>

<?php
$file = 'somefile.txt';
$remote_file = 'readme.txt';
$ftp_user_name = 'myusername';
$ftp_user_pass = 'mypassword';
$ftp_server = 'ftp.bowhuntr.net';

// set up basic connection
$conn_id = ftp_connect($ftp_server);

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// upload a file
if (ftp_put($conn_id, $remote_file, $file, FTP_ASCII)) {
echo "successfully uploaded $filen";
} else {
echo "There was a problem while uploading $filen";
}

// close the connection
ftp_close($conn_id);
?>
</body>
</html> [/code]
with your code, taking out all the necesary parts and inserting the correct stuff please and could u please tell me if i need to make any changes with the form [code=html]<html>
<body>


<!-- The data encoding type, enctype, MUST be specified as below -->
<form enctype="multipart/form-data" action="php.php" method="POST">
<!-- MAX_FILE_SIZE must precede the file input field -->
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
<!-- Name of input element determines name in $_FILES array -->
Send this file: <input name="userfile" type="file" />
<input type="submit" value="Send File" />
</form>

</html>
</body>[/code]
please and thanks so very much
Copy linkTweet thisAlerts:
@SheldonNov 25.2005 — [code=php]
<html>
<body>

<?php
// path to save file to
$UploadDir = 'images/uploads/';
$UploadFileName = $UploadDir . $_FILES['userfile']['name'];

if (move_uploaded_file($_FILES['userfile']['tmp_name'], $UploadFileName)) {

print 'Photo upladed';

}else{

print 'error';

}//end this upload form

?>
</body>
</html>
[/code]
Just set the default path ie: [b]$UploadDir = 'images/uploads/'; [/b]
Copy linkTweet thisAlerts:
@Heavy_MetalauthorNov 25.2005 — ok thank you soooooooooooooooooooooooooooooo(a google of o's) much


EDIT: ok its not doing anything, its not giving me an error or being succesful or anything what is the problem?
Copy linkTweet thisAlerts:
@bokehNov 25.2005 — Here is a quick upload script I've thrown together for you, with password protection and some error checking. The password is [I]password[/I] at the moment. You can change the destination directory but right now it is set so the upload goes to the same directory the script is located in.[code=php]<?php
define('PASSWORD', 'password'); // edit second argument
$destination_directory = './'; // fill in
$errors = array('1' => 'file size over PHP limit', '2' => 'file size over form limit',
'3' => 'file only partially uploaded', '4' => 'no file specified');

$form = '
<form action="'.$_SERVER['PHP_SELF'].'" enctype="multipart/form-data" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
Password: <input type="password" name="password" value="'.@$_POST['password'].'"><br>
Upload: <input type="file" name="file"><br>
<input type="submit" name="submit" value="Upload">
</form>
';

(@$_POST['submit'])
or exit($form);
(PASSWORD == $_POST['password'])
or exit('<span style="color:red;">Incorrect password</span><br><br>'.$form);
(!(@$_FILES['file']['error']))
or exit('<span style="color:red;">Upload error: '.$errors[$_FILES['file']['error']].'</span><br><br>'.$form);
(!file_exists($destination_directory.$_FILES['file']['name']))
or exit('<span style="color:red;">Error: a file with that name already exists</span><br><br>'.$form);
(@move_uploaded_file($_FILES['file']['tmp_name'], $destination_directory.$_FILES['file']['name']))
or exit('<span style="color:red;">Error: not allowed</span><br><br>'.$form);
print 'File saved ok. <a href="'.$_SERVER['PHP_SELF'].'">Upload another?</a>';
?>[/code]
Copy linkTweet thisAlerts:
@Heavy_MetalauthorNov 25.2005 — EDIT:nvm u didn't mess up
Copy linkTweet thisAlerts:
@bokehNov 25.2005 — im pretty sure u messed up somehow[/QUOTE]Really! There is nothing wrong with that script. Did you actually try to run it?
Copy linkTweet thisAlerts:
@SheldonNov 25.2005 — Good call Bokeh!. I think your script is great and took a copy for myself for use later on ? nice work !
Copy linkTweet thisAlerts:
@Heavy_MetalauthorNov 25.2005 — well if u will look i said nvm u didn't mess up but it still returns a "Error: not allowed" message whenever i try to upload it
Copy linkTweet thisAlerts:
@bokehNov 25.2005 — That error is occuring while trying to move the uploaded file from the temp directory to the destination directory. The most likely cause is that you don't have sufficient permission to write to the destination directory.
Copy linkTweet thisAlerts:
@Heavy_MetalauthorNov 25.2005 — well im setting it to the "/" directory and i "write to" it all the time

more actueratly it says in that spot "./" so is that wrong?
Copy linkTweet thisAlerts:
@SheldonNov 25.2005 — whats is your permissions on the directory you are trying to upload in to? needs to be at lease 744 or 755 but for now try 777
Copy linkTweet thisAlerts:
@Heavy_MetalauthorNov 25.2005 — the / is the main one like if u put index.htm(l) in it then type in the main domain name it takes u to it and i use filezilla to log into my ftp account and so it shows the directory off of the main one but i cannot go above the public level but i should have 777 write permissions but i cannot tell you for sure

EDIT:could we all just get on msn aim or yim so we wouldn't have to waste space on here?
Copy linkTweet thisAlerts:
@bokehNov 25.2005 — well im setting it to the "/" directory and i "write to" it all the time

more actueratly it says in that spot "./" so is that wrong?[/QUOTE]
'./' refers to the directory the script is located in but you could try specifying with an absolute path as follows:[code=php]//The following specifies the root directory
$destination_directory = $_SERVER['DOCUMENT_ROOT'].'/';[/code]
Copy linkTweet thisAlerts:
@SheldonNov 25.2005 — no it wont have 777 file permissions your root dir will be set to 644, Create a new folder, put the script in it or change this line in the code, then chmod the perms of the new folder to 777 for now and 755 once you know the script works

[code=php]
$destination_directory = './,new_folder_name_here>'; /* add the new folders name with the 0777 chmod /*
[/code]
Copy linkTweet thisAlerts:
@SheldonNov 25.2005 — Im going to the pub see you all on monday. Good luck

(its friday 4pm here)
Copy linkTweet thisAlerts:
@Heavy_MetalauthorNov 25.2005 — well since it is hosted on my local directory and i can change the write permissions on there i set the write permissions for it to 777 and it still gives me the same error
Copy linkTweet thisAlerts:
@bokehNov 25.2005 — [B]Note:[/B] [I]From the manual [/I]The current user is the user under which PHP runs. It is probably not the same user you use for normal shell or FTP access. The mode can be changed only by user who owns the file on most systems.

I'm going to bed. It's 4am here.
×

Success!

Help @Heavy_Metal spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...