Solved

rename function does't work!

Posted on 2008-06-19
5
206 Views
Last Modified: 2009-09-23
Hello group,

I need to rename a file as soon as it is uploaded on server so I'm using rename function as following:

rename($flash_file, $_SERVER["DOCUMENT_ROOT"] . "/apps/game/flash/" . $modified_name);

What have I missed here?!

Thanks.
0
Comment
Question by:akohan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 24

Expert Comment

by:glcummins
ID: 21825747
$new_filename = $_SERVER["DOCUMENT_ROOT"] . "/apps/game/flash/" . $modified_name;

if (file_exists($flash_file))
{
  if (is_writable($flash_file))
  {
      rename($flash_file, $new_filename);
  }
  else
  {
      die("$flash_file is not writable.");
  }
}
else
{
   die("$flash_file does not exist.");
}
0
 
LVL 24

Accepted Solution

by:
glcummins earned 125 total points
ID: 21825763
Sorry, this may be a little better:
$new_filename = $_SERVER["DOCUMENT_ROOT"] . "/apps/game/flash/" . $modified_name;
 
if (file_exists($flash_file) && is_readable($flash_file))
{
  if (is_writable($new_filename))
  {
      rename($flash_file, $new_filename);
  }
  else
  {
      die("$newFilename is not writable.");
  }
}
else
{
   die("$flash_file does not exist or is not readable.");
}

Open in new window

0
 

Author Comment

by:akohan
ID: 21826037


Yes, thank you so much. So what was wrong with calling rename() by itself? was the checking block?


Regards.
0
 
LVL 24

Expert Comment

by:glcummins
ID: 21826120
The way you posted the first time, there was no checking (at least according to the way the question was posted). This method merely makes sure that everything is in place before actually trying to run the rename function. If any one of the checks fails, the rename() function will never run.
0
 

Author Comment

by:akohan
ID: 21826797

Thanks for sharing it.

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question