Jump to content

where and why PHP copy() fails?


krishna.p

Recommended Posts

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

Link to comment
Share on other sites

A copy() will fail if there is a problem with the source or destination (the path does not exist or is wrong relative to the current script - source/destination, the file does not exist - source, php does not have permission to access the path or file, or any other problem that could occur, like a disk error or resource problem...)

 

Turn on full php error reporting to get php to tell you why it is failing. Add the following two lines after your first opening <?php tag -

 

ini_set ("display_errors", "1");
error_reporting(E_ALL);

Link to comment
Share on other sites

Can't tell you any specific information until you provide specific information that identifies what is different when it fails.

 

My guess is that your upload fails due to the file size and you code has no error checking of the upload status to neither check if the upload worked/failed or to output a meaningful message about what happened and blindly continues executing the copy() code.

Link to comment
Share on other sites

It is not the case with upload failure. upload seems successful as my upload_max_filesize is set to 200MB in php.ini. To be breif let me clarify you.

The code is

$tp = substr(md5(uniqid(rand(), true)),0, 10);

if(! $_FILES['f']['error'] == 0)

    die_log("uploading failed.");

if(! copy($_FILES['f']['tmp_name'], "./directory/{$tp}"))

            die_log("unable to copy.");

you have mentioned something like disk error or resource problem. what actually it is? please help me..thanks in advance..

 

Thanks,

krishna.p

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.