Upload path problem

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
lip9000
Forum Newbie
Posts: 11
Joined: Tue Jul 04, 2006 3:38 am

Upload path problem

Post by lip9000 »

I've got an upload script for a photo gallery that I've created which has accepts a URL parameter called 'album' and according to woteva that parameter is finishes the path for the image to be uploaded to. However I'm not sure that the way I've done it is correct because it's not working.
Can someone look at the code and tell me the correct code to replace it with.

$album = $_GET['album'];
$multi_upload->upload_dir = $_SERVER['DOCUMENT_ROOT']."/mirrabookahs/p/albums/$album/"

As you can see the url parameter album gets assigned to the variable album, then gets inserted into the next line, however does not work. The image just gets uploaded to /mirrabookahs/p/albums. NOTE that the album folder is already created so it's not as if the folder isn't there.

Also I don't get any PHP errors when I run this script, it says the image is successfully uploaded.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

try

Code: Select all

error_reporting(E_ALL);
ini_set('display_errors', true);

if ( !isset($_GET['album']) ) {
  echo '<div>Parameter <i>album</i> missing</div>';
}
else if ( preg_match('![^0-9a-zA-Z-_]!', $_GET['album']) ) {
  echo '<div>only a-zA-Z, digits and dashes allowed in <i>album</i></div>';
}
else {
  $multi_upload->upload_dir = $_SERVER['DOCUMENT_ROOT']."/mirrabookahs/p/albums/$_GET[album]/";
  echo '<div>Debug: upload_dir=', $multi_upload->upload_dir;
}
lip9000
Forum Newbie
Posts: 11
Joined: Tue Jul 04, 2006 3:38 am

Post by lip9000 »

my script still runs but the image does not get put into that folder. Are the folders allowed to have spaces in them? coz originally i had the upload folder set as 'My Album' and the "Debug: upload_dir" didnt show up. But when i changed it to 'Myalbum' the "Debug: upload_dir" showed the correct location, but again when i run the script it doesn't get put into that folder, or any folder.

I get this other error:

Warning: mkdir() [function.mkdir]: File exists in C:\wamp\www\phpnuke\html\mirrabookahs\admin\gallery\upload_class.php on line 150

I am including a class file which as you can see is trying to create the folder called "$_GET[album]" because it does not exist and it giving me an error due to a bad name.

So again it is not pulling the value of the variable, rather it's actually looking for a folder under the name of "$_GET[album]"
Post Reply