Re: Input variable from form help request

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 29 September 2011 13:30, PHProg <phprog@xxxxxxxxxxxxxxxxxxx> wrote:
> <?php
> if(!@copy('http://mydomain.com/files/
>
> ".$_POST['trakname']."','/".$_POST['dirname']."/".$_POST['trakname']."'))
> {
>    $errors= error_get_last();
>    echo "COPY ERROR: ".$errors['type'];
>    echo "<br />\n".$errors['message'];
> } else {
>    echo "File copied from remote!";
> }
> ?>
>

Try ...

<?php
if(!@copy("http://mydomain.com/files/{$_POST['trakname']}",
"/{$_POST['dirname']}/{$_POST['trakname']}")) {
	$errors= error_get_last();
	echo 'COPY ERROR: ', $errors['type'], '<br />', PHP_EOL, $errors['message'];
} else {
	echo 'File copied from remote!';
}
?>


You need to keep track of the opening and closing quotes (single and double).

In the copy() function, I'm using the embedded variable method (a
string using double quotes will evaluate the variables at run time).

In the echo statements, I'm not using concatenation as, theoretically,
it should be faster as the echo statement will not need to first build
the concatenated string before echoing it. It will just push the
values out the to the web server. I think. I've not done any metric
testing on that.



As for copying a file TO a http URL, you need to obey the rules of
http. CURL or FTP will be the protocols of choice here, though you do
have the option of using a stream context to wrap the
file_put_contents() into a POST form to the site (similar to CURL in
some ways).
-- 
Richard Quadling
Twitter : EE : Zend : PHPDoc
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY : bit.ly/lFnVea

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux