Jump to content

Uploading script change file name depend on URL


Recommended Posts

Website URL on address bar :

http://www.mydomain.com/copy/upload3.php?name=asdas.txt

 

Using following script to upload files to another FTP server

 

Originally script work fine :

 

I have a file name asdas.txt ( File name changes so I have to get the file that I want to upload from website URL that’s why I use $_get) on my website I want to upload that to remote server.

 

I changed following

 

Add : $txt1=$_GET['name'];

Changed : 4th line example.txt to $txt1'

Changed : 4th from last line /example.txt to /$txt1

Changed : 4th from last line example.txt to $txt1

 

<?php

ob_start();

$txt1=$_GET['name'];

  if(!file_exists('$txt1')) echo "File not found";

  //ftp details of sedtination server 

  $ftp_server="server ip";

  $ftp_user="username";

  $ftp_password="pass";

 

  $conn_id = ftp_connect($ftp_server);

  $login_result = ftp_login($conn_id, $ftp_user, $ftp_password);

 

  if((!$conn_id) || (!$login_result))

  {

            echo "FTP connection has failed!";

            echo "Attempted to connect to $ftp_server for user $ftp_user";

        exit();

      }

 

  $upload = ftp_put($conn_id,'/$txt1', '$txt1', FTP_BINARY);

  if (!$upload) { echo 'FTP upload failed!'; }

ob_end_flush(); 

?>

 

Is there is a way to fix above script.

 

When user register on my website, it create UserName.txt (UserName unique to each user) I want to upload that user txt files to my other server.

 

This script work well if exact file typed instead of the $txt1

if(!file_exists('$txt1')) echo "File not found";

 

any fixes

 

 

Is the file you want to transfer/copy actually on your original server? I mean has it been created already by the time this script executes? Can you navigate to it using the URL bar of your browser? Otherwise, it just sounds like it cant find the actual file (the .txt) on your server.

 

Try echoing the the $txt1 variable and see if you get an absolute or relative path to the file. If it is just "asdas.txt". that is wrong. unless that file is in the same directory as this script. Otherwise, it must be"../asdas.txt" or "www.example.com/directory/asdas.txt".

yes at the time i am running the script file is on my web hosting server. i want to transfer it to by dedicated server

 

when i put echo "$txt1";

i get follong msg

asdas.txt

 

yes file is on the same directory as the script file.

 

 

could the error on following line

 

$upload = ftp_put($conn_id,'/$txt1', '$txt1', FTP_BINARY);

 

 

 

strange:

when i rename my file name to $txt1

it upload the file,

 

but i want the file name to be name

 

already define

$txt1=$_GET['name'];

 

but it dont get name from URL

 

 

any fixes.

 

if you have any working script that up load files from website to a remote dedicated server. please post it.

 

Note : name of the file generated on the web server changes depend on user name

it look like this, what ever the user name is . txt

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.