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
Solved

rename function does't work!

Posted on 2008-06-19
5
205 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
  • 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

792 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