Jump to content

Request guidance with coping and renaming a file


IChaps

Recommended Posts

Hello.

I'd just like to ask about coping a picture file from one folder to another, then rename the copied file.  At present I've written:

$mstr_dir = "/core/graphics/";
$fle = "noimage.png";
$usr_folder = "/core/user/images/";


if (!copy("/core/graphics/noimages.png" , "/core/user/images/noimages.png")) {
    echo "ERR: ". error_reporting(E_ALL) . ini_set("display_errors", 1) . "<br>";
}


error_reporting(E_ALL);
ini_set("display_errors", 1);
chmod("noimage.png",0777);
$up_file = $last_id . ".png";


rename ('/core/user/images/noimages.png' , '/core/user/images/' . $up_file);

 

However I'm getting the error number 22519, and the file is not been copied.  I've already checked the path names and they do exist.

Also with copy, I have tried " and ' both don't work.

I'd just like to ask if theres an error in my code that I'm missing, and  any idea what the error number 22519 refers to?

Thank You.

Link to comment
Share on other sites

That's not an error code, it is the previous value for error_reporting.  You're trying to print the return values of error_reporting and ini_set.  Both of those functions are for setting options in PHP, they don't provide any information about any errors that happen.  error_reporting lets you set a new error reporting value and it returns the old one (you can break down 22519 if you really want to see which options that enables), and ini_set sets one of the PHP runtime options.

You should use both of those functions at the top of your code to set the error options so that when an error happens, like with the copy function, PHP prints the actual error message.  You don't set the error reporting settings until after using copy, so any error that happened will be ignored unless it's printing to an error log or something else.

Also, there's not much of a reason to copy and then rename, you can copy the file with the new name.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...