Jump to content

problem uploading images to different directories


angryjohnny

Recommended Posts

I have a simple PHP script that lets the user upload images to a directory on my server.

 

$uploaddir = 'images/';

$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

 

if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {

echo "File is valid, and was successfully uploaded.";

}

 

Which works fine. This scipt as you can see will upload an image to a directory, path: images/imagename.jpg. What I'm trying to do is set a variable for "images/" called "$folder". So depending what link the user clicked on to get to the upload page, this variable changes allowing images to be uploaded to different directories. So my first thought was to simple change this line to get it working:

$uploaddir = 'images/';

to

$uploaddir = $folder;

The variable $folder is being read properly but when I submit the form to upload the file it leaves out the $folder and just writes the image name uploading it to the same directory the file is in.

I have tried 100 different ways to get this to work. I have found a way to get it to work but its not very sufficient.

Can someone please help.

 

Thank you

John

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.