Jump to content

copy() with and "&" in the file name


severndigital

Recommended Posts

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

 

 

Link to comment
https://forums.phpfreaks.com/topic/266335-copy-with-and-in-the-file-name/
Share on other sites

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';
}	

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.

 

 

 

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.