Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2014-07-22
4
Medium Priority
?
7,035 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 2000 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

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

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…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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 count occurrences of each item in an array.

721 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