Click to See Complete Forum and Search --> : Upload using FTP


Cipher
11-25-2005, 07:39 AM
I want to upload files to server using FTP connection, i have the script to do this and it works, the problem is i want to enable users to upload files, so i used file control to upload, the problem is i cant get the full name of file with its path from the file controli tried $_FILES["file1"]["tmp_name"] but it didnt work coz it shows the path of the temp folder, and i need the actual path of the folder, the only way i found to get is with JS
var fullName = document.form1.file1.value;
so, how can i pass it to PHP?!

Stephen Philbin
11-25-2005, 07:44 AM
You don't need that address. It is useless to you.

$_FILES["file1"]["tmp_name"] Is a copy of the file that the user uploaded. Save that to a permanent location and you're done.

Like so:


<form action="" method="post" enctype="multipart/form-data">
<p>Pictures:
<input type="file" name="pictures[]" />
<input type="file" name="pictures[]" />
<input type="file" name="pictures[]" />
<input type="submit" value="Send" />
</p>
</form>

<?php
foreach ($_FILES["pictures"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$tmp_name = $_FILES["pictures"]["tmp_name"][$key];
$name = $_FILES["pictures"]["name"][$key];
move_uploaded_file($tmp_name, "data/$name");
}
}
?>

Cipher
11-25-2005, 07:55 AM
Well, i just want to get the full name of the file, i dont understand how can i get the name from this script, coz i wont use move_uploaded_file function, i'll use ftp
ftp_put($ftp, "string_remote_file", "string_local_file", FTP_BINARY);

Stephen Philbin
11-25-2005, 08:10 AM
Why would you use switch to FTP functions when you already have the file from the form? The way I look at them, FTP functions are generally for building FTP applications that you actually install on a client machine. They're pretty much pointless otherwise.

Cipher
11-25-2005, 08:17 AM
Well coz i'm having problem with server settings, that dont allow me to upload more than 2MB, and i discussed this before and what i reached that i must contact the server and make them change settings for me, untill that, i need to upload more than 2MB, so i thought to try the ftp, maybe it will solve it. here's the topic (http://www.webdeveloper.com/forum/showthread.php?t=85151&highlight=php.ini)

bokeh
11-25-2005, 09:11 AM
i need to upload more than 2MB, so i thought to try the ftp, maybe it will solve it. here's the topic (http://www.webdeveloper.com/forum/showthread.php?t=85151&highlight=php.ini)
Why don't you impliment the advice from the other thread?

Cipher
11-25-2005, 11:48 AM
well it didnt work, and some people i know, said the only solution is to make the server adminstrators change the settings to you.

bokeh
11-25-2005, 12:36 PM
some people i know, said the only solutionTalk is cheap and usually the comments are negative. Let's restart the discussion. Most problems do actually get solved in this forum. The code I posted worked. If it doesn't work for you maybe it's in the wrong file or the wrong location.

Cipher
11-25-2005, 07:37 PM
well thank you, i just did as you said, and it gave me the same error, and someone told me that .htaccess wont work even if it worked without errors, it wont have any effect.

SpectreReturns
11-26-2005, 12:19 AM
Ok, here's what happens:

Form -> File Input. This will UPLOAD the file onto your server in a temporary location. Then you need to move it out of temp into a permanent location. FTP is used to transfer files, but since they've already been uploaded via HTTP there is no way to use FTP in this manner, and even if it wasn't uploaded, the user would need to have a local script to upload via FTP.

bokeh
11-26-2005, 10:44 AM
someone told me that .htaccess wont workWell then someone is talking rubbish. The following works.php_value post_max_size 75M
php_value upload_max_filesize 25M
php_value max_input_time 90I know it works because I tested it. After it is placed in .htaccess in the root directory those settings are changed. If that doesn't work for you then it is most likely you are placing it in the wrong file or location. Since you have other items running from .htaccess it is obvious .htaccess is enabled on your server.

Cipher
11-27-2005, 07:11 AM
well i want to ask if it shall work localy on my pc, coz it has no effect when i do it on my pc.

bokeh
11-27-2005, 08:59 AM
It should work if:
1) Your server is Apache
2) AllowOveride All is set in httpd.conf (default)
3) The above 3 lines have been placed in .htaccess
4) .htaccess is located in your root directory
5) max_input_time is long enough to accept the input

I have just tested this on my server and had no trouble uploading a 10 megabyte file.

What makes you think the changes to .htaccess are not having any effect?

Cipher
11-27-2005, 07:53 PM
well would you tell me how to write this line: AllowOveride All?!
is it just as u wrote it?!

Sheldon
11-27-2005, 07:58 PM
by default it is on, but yes as it is written in the httpd.conf file on your server.

bokeh
11-28-2005, 03:32 AM
Copied from httpd.conf (default)

# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride All

Also if you are in control of the server these php values can be run from the virtual host.

Cipher
11-28-2005, 07:25 AM
may you try this link (http://www.islam-christianity.org/info.php) and tell me what you think, i tried what you told me and its same error page.

bokeh
11-28-2005, 09:19 AM
I tested this on my server. Changes to the .htaccess file in my root directory cause the values in the left column of phpinfo to change to the value set in .htaccess.

At present your settings are:

post_max_size 55M
upload_max_filesize 2M
max_input_time -1

I have never seen that -1 but maybe someone can tell us what it means.
Start again with .htaccess and only include the three lines I posted. Place it in the root directory and recheck your phpinfo. If you do not see changes either .htaccess is not allowed or .htaccess is not in the root directory.