Solved

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

Posted on 2014-07-22
4
6,452 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
[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
4 Comments
 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 40210978
0
 
LVL 31

Accepted Solution

by:
Marco Gasi earned 500 total points
ID: 40210986
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
1
 
LVL 3

Expert Comment

by:stevejacob68
ID: 40210993
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
ID: 40211153
thank you  for your help
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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

617 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