Would someone please be able to help with a file upload via pm?! :(

Apologies for the strange request, but I’m doing a website for a school and need to present it to the headteachers secretary tomorrow, so I don’t really want to leave any sort of folder upload stuff available to hundreds of people online as all sorts could happen with it! :slight_smile:

I’ve basically got a system where you can add a folder using PHP, which CHMODs the folder to 0777, and you can upload pictures to that folder - but umm, for some reason the upload isn’t working, unless you upload to a folder that I created manually.

If someone wouldn’t mind PM’ing me about it I’d really appreciate it, I’m completely stuck :frowning:

Thanks!

You should be looking in your error log to find out some clues about the problem, likely to be a chown/chgrp issue.

what error checking are you doing? are you checking that the permissions are 0777 before trying the upload?

Post your code rather than getting people to pm you, unless of course it is highly sensitive in which case let me know :slight_smile:

Huge thanks guys - I’ll look into the chown/chgrp thing now, although I must say I’m not familiar with them at all!

It’s probably not too sensitive, I think - I’d post the link if it wasn’t for the fact I had to give a demonstration on it later!

Here’s the actual part of the code that creates the folders, and writes to them :slight_smile:

	/* Add a new gallery? */	
	if(isset($_POST['add_gallery'])) {
		$old_umask = umask(0);
		mkdir("../gallery/" . $_POST['gallery_category'],0777);
		umask($old_mask);
	}
	/* Upload a document? */
	if(isset($_POST['upload'])) {
	
		$upload_folder = '../gallery/' . $_POST['gallery_category'] . '/';

		// set the file's target
		$target = $upload_folder . time() . '-' . basename($_FILES['uploaded']['name']);

		// no nasty files please
		if (($_FILES["uploaded"]["type"] == "image/gif")
		|| ($_FILES["uploaded"]["type"] == "image/jpeg")
		|| ($_FILES["uploaded"]["type"] == "image/png")
		|| ($_FILES["uploaded"]["type"] == "image/pjpeg")
		|| ($_FILES["uploaded"]["type"] == "image/x-png")) {

			if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) {
				echo '<div class="message">The file <strong><a href="'.$target.'">'. basename($_FILES['uploaded']['name']). '</a></strong> has been uploaded, thank you.</div><br>';
			}
			else { echo '<div class="messageRed">Sorry, there was a problem uploading your file.</div><br>'; }

		} else { echo '<div class="messageRed">Please only upload image files!</div><br>'; }
	
	}

If you need any of the HTML please let me know, and to be honest I’m not too adverse to posting a link to the working copy, as I do trust the users on this site, probably just being overly cautious atm :slight_smile:

Quick bump on the hope I could maybe fix it by 2:30 today :smiley:

Its like we said “error log” and “error checking” and you didn’t hear it.

Maybe you don’t know what we mean? [google]php errors[/google]

Ahh! I see thanks Cups, sorry just used some of the error reporting code and it says this:

Warning: move_uploaded_file(): SAFE MODE Restriction in effect. The script whose uid is 10170 is not allowed to access /var/www/vhosts/heywood.gloucs.sch.uk/httpdocs/gallery/Testing owned by uid 48

Just tried this, unfortunatley no joy:

ini_set(“safe_mode”, 0 );

You could just take the umask references out and leave the mkdir to do its thing. See if it makes a difference

Good shout thanks spikeZ, I tried that but I get the same error unfortunately:

Warning: move_uploaded_file(): SAFE MODE Restriction in effect. The script whose uid is 10170 is not allowed to access /var/www/vhosts/heywood.gloucs.sch.uk/httpdocs/gallery/Hey owned by uid 48

Also without the umask thing it sets the CHMOD to 755, which I think doesn’t work right then either :frowning:

Good shout actually thanks Cups, about the Flickr thing! I’m guessing it’s fairly easy to display those photos from Flickr onto some kind of gallery on the school’s website? Would save a lot of messing around then too, great idea!

(although I am using this image upload thing as a tool for the CMS as well - bit of a pain, but I can’t seem to find a decent image upload plugin for NicEdit!)

That server has safe_mode turned on and it means that the script trying to do the moving must have exactly the same owner (an maybe group) as the file it is trying to move.

chown, chgrp.

You ideally need to sftp into the server and use “ls -l” command to find out what is going on.

(and hey, for a school, why don’t you just train users to put the images on Flickr anyway? - are they all going onto the internet anyway?)