webtotaltoday
Posts: 46
|
| Posted: 06/17/2007, 4:30 AM |
|
Hi,
Due to bandwidth issues i have had to move our website to another server but not the files just the bulky uploaded files.
The problem i have is i cannot get the upload to work with another domain eg:
http://www.domain.com/files/
i have also tried ftp eg:
ftp://username:password@domain.com/files
but nothing is working.
Can please someone help?
|
 |
 |
wkempees
Posts: 1679
|
| Posted: 06/18/2007, 5:29 AM |
|
S,
Fileupload process (PhP) has a few things that should be known from the start.
It is a process that will accept the source file, upload it to a temp directory and then your file upload setting are checked against it (file mask, file size), when ok the process will rename in fact copying the file to the target directory. as a final step the CCS FileUpload Component will store the new name in order to be able to display the file if and when you want it.
That said, a rename (move/copy) from your (local) file server to another domain will AFAIK not be accepted. It would then be to easy to flood someone elses server, wouldn't it?
The way to accomplish the task at hand I will describe in the next post.
Discalimer, the next post will describe the functional way to copy an uploaded file to a different server, however it does not cater for the filechecks done by the fileupload component nor does it supply a rigid description of storing the new full path in such a way that in another part of your application you can easily redisplay the file (assuming it is an image).
The way to store the new path is described though.
Walter
_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)
if you liked this info PAYPAL me: http://donate.consultair.eu
|
 |
 |
wkempees
Posts: 1679
|
| Posted: 06/18/2007, 5:46 AM |
|
Starting point is a fully functional FileUpload Component.
Meaning, it flawlessly uploads your file at this point, temporary and upload directories are set and accessible, the component does not report any errors and the uploaded files are reaching their destination.
In CCS Design mode select the FileUpload Component and in the Properties switch to events.
Right click the AfterProcessFile and "Add Code".
(The next snippet is adapted straight from the PhP manuals, all credits due)
Enter the following code:
// Write your own code here.
// -------------------------
// set up basic connection
$ftp_server = "ftp.domain.tld"; // as you would in any ftp session
$ftp_user_name = "username"; // same here
$ftp_user_pass ="password"; //ditto
$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!"; // replace the echos later on with any logging you use
echo "Attempted to connect to $ftp_server for user $ftp_user_name";
exit;
} else {
echo "Connected to $ftp_server, for user $ftp_user_name";
}
// upload the file
$destination_file = "path on target server as seen by ftp" . $Component->GetValue();
$source_file = "../images/" . $Component->GetValue();
$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);
// check upload status
if (!$upload) {
echo "FTP upload has failed!";
} else {
echo "Uploaded $source_file to $ftp_server as $destination_file";
// MARKER
}
// close the FTP stream
ftp_close($conn_id);
//End Custom Code
This will do the transfer to the other server if all parms are set ok.
Where it says //MARKER
$fname = $Component->GetValue();
$fullURL="http://www.domain.tld/path/path/";
$Component->SetValue( $fullURL . $fname);
would give you the opportunity to store the full URL to your uploaded file for future linking.
(The echo statements throughout the code will display the various steps for debugging purposes, you will have to delete or comment out some of them).
Open issues are (as stated):
Do we delete the source file, it would cater for the storage problem but need to be handled properly in order for the FileUpload Component not to fail it's error checks (you could replace the file with a one byte placeholder).
How to act upon delete of the File.
and so on, but hey you asked for a HowTo not a DoMe.
Walter
(tested btw)
_________________
Origin: NL, T:GMT+1 (Forumtime +9)
CCS3/4.01.006 PhP, MySQL .Net/InMotion(Vista/XP, XAMPP)
if you liked this info PAYPAL me: http://donate.consultair.eu
|
 |
 |
AQUANANU
Posts: 107
|
| Posted: 07/19/2007, 3:34 AM |
|
has anyone tried this using ASP
_________________
Navneet Kakkar
CEO
Positive Thinker's Inc. |
 |
 |
|