Solved

how to move a file/photo to an folder using php?

Posted on 2014-07-22
4
4,062 Views
Last Modified: 2014-07-22
Hi experts,

how to move a file to  a new folder using php?

thx.
0
Comment
Question by:tjome
4 Comments
 
LVL 36

Expert Comment

by:Loganathan Natarajan
Comment Utility
0
 
LVL 30

Accepted Solution

by:
Marco Gasi earned 500 total points
Comment Utility
You have to do it in two steps: first you have to copy the file using copy function , then you have to delete the source file using unlink function:
$source = "path_to_file/image.jpg";
$dest = "new_path_to_file/image.jpg";
copy($source, $dest);
unlink($source);

Open in new window

Please, be sure the new destination directory exist and be sure to have write permission on it.

Cheers
0
 
LVL 3

Expert Comment

by:stevejacob68
Comment Utility
Hi,

This code will move file to another folder in php:

if(isset($_POST['next_page'])) {
  if (!is_dir('../images/uploads/listers/'.$_SESSION['loggedin_lister_id'])) {
    mkdir('../images/uploads/listers/'.$_SESSION['loggedin_lister_id']);
  }

  foreach($_SESSION['uploaded_photos'] as $key => $value) {
    $target_path = '../images/uploads/listers/'.$_SESSION['loggedin_lister_id'].'/';
    $target_path = $target_path . basename($value);

    if(rename($value, $target_path)) {
      echo "The file ".  basename($value). " has been uploaded<br />";
    } else{
      echo "There was an error uploading the file, please try again!";
    }

  } //end foreach

}
0
 

Author Closing Comment

by:tjome
Comment Utility
thank you  for your help
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Responsive Design Tools 6 36
Page showing diff display 4 19
wordpress issue 2 15
Wordpress Body Class 5 8
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…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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 look for a specific file type in a local or remote server directory using PHP.

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now