Link to home
Start Free TrialLog in
Avatar of tjome
tjome

asked on

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

Hi experts,

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

thx.
Avatar of Loganathan Natarajan
Loganathan Natarajan
Flag of India image

ASKER CERTIFIED SOLUTION
Avatar of Marco Gasi
Marco Gasi
Flag of Spain image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of stevejacob68
stevejacob68

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

}
Avatar of tjome

ASKER

thank you  for your help