Jump to content

How would i upload file using ftp and php?


Liquid Fire

Recommended Posts

well i do that and when i run the script from the live server i get this error:

Warning: ftp_put(c:/test.gif) [function.ftp-put]: failed to open stream: No such file or directory in /home/.ornate/kdiadmin/kaizendigital.com/wowguild/includes/ftp.php on line 134

Now When I run the file on my local machine the file get uploaded to the live server like it should and the file does exist on my machine at c:\test.gif.  The only thin gi can think of is that the script is looking for c:\test.gif on the machine the server is running from and if not then what do i have to do different to get it to work on the live server becuase if work great when i run it on my machine on my localhost.
Link to comment
Share on other sites

[code]
$upload_file_path = $_POST["filedirectory"] . $_POST["filename"];
if($ftp->UploadFile($upload_file_path, $_POST["filename"], FTP_TEXT))
{
    print("Image Uploaded.");
}
else
{
    print("Could not upload image.");
}
[/code]
[code]
public function UploadFile($local_file_path, $server_file_path, $file_type)
{
if(ftp_put($this->GetFTPConnection(), $server_file_path, $local_file_path, $file_type))
{
return true;
}
else
{
return false;
}
}
[/code]

that is all the code you need to know that deals with my problem.
Link to comment
Share on other sites

Just a quick stab in the dark here and I'm new but should this line contain the filename?

[code]
$upload_file_path = $_POST["filedirectory"] . $_POST["filename"];
[/code]

The path for the file to be uploaded should not have the file name in it right? not sure

Cheers!
Stephen

Link to comment
Share on other sites

If you read my code you would notice the the $upload_file_path is the path to the file that is being uploaded.  And according to this http://sg.php.net/manual/en/function.ftp-put.php, you do need the file name for the file on the server. 

Anyone else see anything wrong?

Does ftp_put look for the file on the machine the script is running on( as in the server machine ) or the machine that is accessing the script( as in the user-end machine, which is where the file is located )?
Link to comment
Share on other sites

Try the following as a troubleshooting tool (it's only temporary):
[code]
$upload_file_path = $_POST["filedirectory"] . $_POST["filename"];
echo "<br />Upload File Path:  " . $upload_file_path;          //    <--Add this line and re-run the script.  See if anything looks odd.
if($ftp->UploadFile($upload_file_path, $_POST["filename"], FTP_TEXT))
[/code]
Link to comment
Share on other sites

No it doesn't.  That line of code will only post one or the other--not both.

I haven't used PHP on windows so I can only assume it follows the windows standard, but windows will NOT understand what c:/test.gif is.  If you're really passing that as your file name/path, then that might very well be your problem.

Then when it can't find the file, you get FALSE as your test value.

Link to comment
Share on other sites

The server is unix, the livwe one and my localhost test server is windows.  when i run the script on my test server,, c:/ or c:\ works and the file gets uploaded but when i run it from my live server, neither works.  the thing that confuses me is that is works on my test server and not on my live server.  the error message i get on the live server is:

Warning: ftp_put(c:\test.gif) [function.ftp-put]: failed to open stream: No such file or directory in /home/.ornate/kdiadmin/kaizendigital.com/wowguild/includes/ftp.php on line 134
Could not upload image.

What that tells me is that is can't find the file which make me to believe that it is not looking on my computer for the file, which is where it is, but it is looking for c:\test.gif on the server machine at the hosting company.  what does that error tell you?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.