severndigital Posted July 27, 2012 Share Posted July 27, 2012 I recently wrote a script that sweeps directories and copies the files to an alternate location. Everything works fine. until someone uploaded a file call 'This & That cover.zip' the script tried to execute but the copy() function returned an error of Severity: Warning --> copy(/home/ftp_root/This ): failed to open stream: No such file or directory /home/web_roots/portal/ci_app/controllers/webservices/ftp_service.php i'm doing anything fancy just a simple copy($source_path.$source_file,$dest_path.$source_file) It seems that the copy command is only seeing the file name as 'This ' instead of 'This & That.zip' Truncating the file name at the ampersand. Any suggestions? I tried googling but was unsuccessful. Thanks in advance, C Quote Link to comment https://forums.phpfreaks.com/topic/266335-copy-with-and-in-the-file-name/ Share on other sites More sharing options...
jazzman1 Posted July 27, 2012 Share Posted July 27, 2012 You could encode a special characters in the string. For example: This & That == This%20%26%20That Of course, you can use urlencode php function (or someone others) to do this. Quote Link to comment https://forums.phpfreaks.com/topic/266335-copy-with-and-in-the-file-name/#findComment-1364848 Share on other sites More sharing options...
scootstah Posted July 27, 2012 Share Posted July 27, 2012 I just ran a script that copied a file called "this & that.txt" using copy() and there was no problems. Post the rest of your code please. Quote Link to comment https://forums.phpfreaks.com/topic/266335-copy-with-and-in-the-file-name/#findComment-1364851 Share on other sites More sharing options...
severndigital Posted July 27, 2012 Author Share Posted July 27, 2012 As requested. Like I said, the script has been working without issue and even handles files with quotes in them. I didn't even think to test it with an ampersand. $err = array(); $notify_all = FALSE; $input = $this->input->post('sourceFile'); $source_path = explode("/",$input); $source_file = array_pop($source_path); $source_path = implode("/",$source_path).'/'; $dest_path = STORAGE.'mega_share_1/Downloaded/Incoming/'; $dest_back = STORAGE.'mega_share_1/Downloaded/Backup/'; if(copy($source_path.$source_file,$dest_path.$source_file)) { //make the backup if(copy($source_path.$source_file,$dest_back.$source_file)) { //remove source file if(unlink($source_path.$source_file)) { //notify everyone log_message('info', 'SUCCESS - controllers/ftp_service/process_ftp_upload copied and removed file: '.$source_file.'.'); $notify_all = TRUE; } else { log_message('error', 'ERROR - controllers/ftp_service/process_ftp_upload could not remove source file: '.$source_file.'.'); $err[] = 'source file '.$source_file.' not deleted'; } } else { log_message('error', 'ERROR - controllers/ftp_service/process_ftp_upload '.$source_file.': backup not made.'); $err[] = 'backup copy not made'; } } else { log_message('error', 'ERROR - controllers/ftp_service/process_ftp_upload '.$source_file.': original copy not made.'); $err[] = 'original copy not made'; } Quote Link to comment https://forums.phpfreaks.com/topic/266335-copy-with-and-in-the-file-name/#findComment-1364865 Share on other sites More sharing options...
jazzman1 Posted July 27, 2012 Share Posted July 27, 2012 Could you put in this code immediately after "$input = $this->input->post('sourceFile')", and give us a result. echo '<pre>'.var_dump($input).'</pre>'; exit; Quote Link to comment https://forums.phpfreaks.com/topic/266335-copy-with-and-in-the-file-name/#findComment-1364873 Share on other sites More sharing options...
severndigital Posted July 27, 2012 Author Share Posted July 27, 2012 ok .. thanks .. that has pointed me the right direction at least. It seems the file is coming into the script without the name correctly. I couldn't use var_dump, but I had $input value written to the log file. //a correct entry. INFO - 2012-07-27 10:48:58 --> var_dump -- /home/ftp_root/web_transfers/TestFile.pdf //one with an ampersand .. file was named .. TestFile & Name.pdf INFO - 2012-07-27 10:49:28 --> var_dump -- /home/ftp_root/web_transfers/TestFile I am using cURL to access this script from incron. like this INCRON entry /home/ftp_root/web_transfers/ IN_CLOSE_WRITE /home/scripts/process_ftp_file.sh $@/$# process_ftp_file.sh contents #!/bin/bash curl -d "sourceFile=$1" http://portal.chernay.com/webservices/ftp_service/process_ftp_upload I will begin debugging the incron and curl inputs. Thanks for your help in getting me to the correct place. for posterity I will post the fix once I get it figure out. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/266335-copy-with-and-in-the-file-name/#findComment-1364883 Share on other sites More sharing options...
severndigital Posted July 27, 2012 Author Share Posted July 27, 2012 The problem with with cURL. I was using -d and when i switch it to --data-urlencode it works. Thanks again for helping me face the right direction. Quote Link to comment https://forums.phpfreaks.com/topic/266335-copy-with-and-in-the-file-name/#findComment-1364891 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.