File upload to multiple dirs

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
mikeeeeeeey
Forum Contributor
Posts: 130
Joined: Mon Jul 03, 2006 4:17 am
Location: Huddersfield, UK

File upload to multiple dirs

Post by mikeeeeeeey »

Hi guys,

Just having a bit of a problem uploading two files (from one form) to two different folders on the server. I can get this working on my local testing server but not online? Online, only the 'release' uploads so far...

Here's my code:

Code: Select all

chdir($_SERVER['DOCUMENT_ROOT'] . "/newsletter/");

if(move_uploaded_file($_FILES['release']['tmp_name'], "releases/$release")){
  chdir($_SERVER['DOCUMENT_ROOT'] . "/newsletter/");
  move_uploaded_file($_FILES['image']['tmp_name'], "images/headers/$image")
    or die("Image upload failed...");
}else{
  echo "Release upload failed";
}
I didn't have to use the chdir() locally, but there's other scripts online which deal with uploads, and I've found myself having to use chdir() before I attempt to upload anything.

Any help much appreciated, thanks in advance!
User avatar
Gente
Forum Contributor
Posts: 252
Joined: Wed Jun 13, 2007 9:43 am
Location: Ukraine, Kharkov
Contact:

Post by Gente »

Try following

Code: Select all

$UploadDir = $_SERVER['DOCUMENT_ROOT'] . "/newsletter/";
if(move_uploaded_file($_FILES['release']['tmp_name'], $UploadDir."releases/$release")){
  move_uploaded_file($_FILES['image']['tmp_name'], $UploadDir."images/headers/$image")
    or die("Image upload failed...");
}else{
  echo "Release upload failed";
}
User avatar
mikeeeeeeey
Forum Contributor
Posts: 130
Joined: Mon Jul 03, 2006 4:17 am
Location: Huddersfield, UK

Post by mikeeeeeeey »

thanks for your reply Gente, but it's failing at the very first hurdle, won't even upload the release...

very weird!
User avatar
Gente
Forum Contributor
Posts: 252
Joined: Wed Jun 13, 2007 9:43 am
Location: Ukraine, Kharkov
Contact:

Post by Gente »

Have you checked the permissions of the folder?
User avatar
mikeeeeeeey
Forum Contributor
Posts: 130
Joined: Mon Jul 03, 2006 4:17 am
Location: Huddersfield, UK

Post by mikeeeeeeey »

FFS!!!!!

every single time! I should have my own forum on here called 'When Mikey forgets to chmod all the folders he potentially works in'.

Gente, like every other member (theres a few) that's breathed the words...
Have you checked the permissions of the folder?
I thank you for pointing this out.

I'm now off to get a tattoo saying '777 Everything' on my hand.
Post Reply