Jump to content

Can upload files - NOT folders though?


wilsonf1

Recommended Posts

Hi im using the following code to upload files to my webserver, but would like it to either upload sub folders as well (assume the folders are already created on live) or..... if it cant upload folders then to skip them and just do the files of the desired directory

while (false !== ($file = readdir($folder))) {				$destination_file = "htdocs/CMS_FILES/". $file;				$source_file = "C:\Inetpub\wwwroot\cms\_websites\/".$website ."\_website/". $file;						if ($file=="dev.asp" || $file=="dev2.asp" ) {				} 				else {					$upload = ftp_put($connection_id, $destination_file, $source_file, FTP_BINARY); 								if (!$upload) { 						echo("<p>FTP upload has failed!</p>");					} 					else {						echo("<li>Uploaded <strong>$file</strong></li>");					}						}					}

when u hit upload targetting a folder which has a sub folder, i get:Warning: ftp_put(C:\Inetpub\wwwroot\cms\_websites\/www_site_com\_website/.) [function.ftp-put]: failed to open stream: Permission denied in C:\wamp\www\php_tests\upload.php on line 71if i remove the sub directory so all i have is a foldre full of files, they go up finePLEASE HELP?

Link to comment
Share on other sites

A single dot refers to the current folder, two dots refers to the parent folder. So it wouldn't work if you try to upload the current folder into itself or put the parent folder in the current folder, so you need to filter those two out.I don't think you use ftp_put for a folder though, I think that's only for files. You're going to need to have some logic to check if the current item is a folder and use ftp_mkdir to create it on the FTP server. Once the folder is created you can use ftp_put on each individual file to move it to the new folder. You can't do a batch upload with a single command, when you open an FTP client and upload a folder you should be able to see that it sends a mkdir command for each subfolder to create and a put command for each individual file, there's not just one FTP command to upload an entire directory tree. You need to do each item individually. So that means checking if each item is a directory or a file and sending the appropriate command, and if it's a directory then you need to read the list of files (and subdirectories) in it and upload each one individually. This sounds like another case for a recursive function. If you're running into permission problems with uploaded items (the error message you posted is a permissions error), you might also need to change the owner or properties for the directory or file after you upload or create it. You can use ftp_chown to change the owner and ftp_chmod to change the permissions.

Link to comment
Share on other sites

  • 1 year later...

Although this topic is old, I would like to share this since it may be useful for so many for FTP uploading entire folders.I am an amateur videographer and have to upload 2-3 folders worth of fashion modeling shots every day to website. Clients select from posted photos. The Subfolders are arranged based on clients/models/promotion dates/promotion types. The manual uploading was annoying, to say the least. Finally began using this script.http://www.biterscripting.com/helppages/SS_FTPUpload.htmlCopies an entire folder to the website and creates subfolders as needed. Try out this if you think this may help.Soj

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...