Solved

rename function does't work!

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

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…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
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 create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

687 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