i really really need your help. I\'m successfully setting up a connection to my ftp server. However I can\'t figure out how I can download a dynamic file from my server. I guess
When I used tempnam()
it changed the file extension to .tmp
. This may cause problems, so I don't recommend doing it this way. At the very least, you should change the extension back to what it was in the original filename.
You can achieve this using pathinfo() in conjunction with regexp and rename(), after you've ftp'ed the file.
Regarding mimetype: You only need this information if you want the browser to display the file you send to the user. For downloads, the browser only needs to know it's a binary file, and the browser or user can guess from the extension.
If you still want to check the mimetype, you'll have to wait until the file is on your server, so the mime-checking code will go inside the if(ftp_get())
block.
You haven't shown your connection code (so I'm assuming), but you will need the full path for the file you're pulling from FTP. If the ftp_get()
step is failing, you're probably requesting an invalid file.
Otherwise, you will have to ftp_chdir() after connecting and logging in so you're in the correct remote folder.
This code worked for me:
If that code doesn't work for you, you may have a problem with permissions, configuration, or some other environment-specific issue.