Hi, iam new to php. please tell me the basic reasons why PHP copy() function fails?
In my application users upload a file and all the uploaded files are copied to one stage folder by giving them randomly created number as file name.
my Sample code is given below.
$tp = substr(md5(uniqid(rand(), true)),0, 10);
if(! copy($_FILES['f']['tmp_name'], "./directory/{$tp}"))
die_log("unable to copy.");
please tell me the reasons why this copy() fails? thanks in advance.
Thanks,
krishna.p
where and why PHP copy() fails?
Moderator: General Moderators
-
WebbieDave
- Forum Contributor
- Posts: 213
- Joined: Sun Jul 15, 2007 7:07 am
Re: where and why PHP copy() fails?
Try this to see if it shed any light on the reason for failure:
Code: Select all
ini_set('track_errors', 1);
$tp = substr(md5(uniqid(rand(), true)),0, 10);
if(!copy($_FILES['f']['tmp_name'], "./directory/$tp"))
die_log("unable to copy: $php_errormsg");Re: where and why PHP copy() fails?
Thanks for the reply..iam seeing success for the most of times but sometimes im getting the error. dont know what is the exact reason why the copy() fails sometimes ? any help would be greatly appreciated.
Thanks,
Krishna.p
Thanks,
Krishna.p
-
WebbieDave
- Forum Contributor
- Posts: 213
- Joined: Sun Jul 15, 2007 7:07 am
Re: where and why PHP copy() fails?
When it fails, $php_errormsg should contain the reason why. Common causes are bad directory and no permissions.
http://us.php.net/manual/en/reserved.va ... rormsg.php
http://us.php.net/manual/en/function.er ... orting.php
http://us.php.net/manual/en/errorfunc.c ... lay-errors
http://us.php.net/manual/en/reserved.va ... rormsg.php
http://us.php.net/manual/en/function.er ... orting.php
http://us.php.net/manual/en/errorfunc.c ... lay-errors