Page 1 of 1

[SOLVED] Copy(); question

Posted: Mon Dec 18, 2006 2:25 pm
by $var
hello, i'm stuggling today to pinpoint why my image upload ceased to work after i switched servers.
the odd thing is, that this exact script is working in a sub-folder of the main site this script is on.

what could be causing nothing to happen? it doesn't redirect at the header(); and nothing copies.

Code: Select all

if($_POST["bpress"]=="Submit") 
	{ 
		//START IMAGE UPLOAD
		$path = $_SERVER["DOCUMENT_ROOT"]."/Imi/Spk_Img/";
		if(!is_dir($path)) { //if $path isn't a dir
			mkdir($path, 0755); //create it
		}
		foreach( $_FILES as $aFile )
		{		
			copy ($aFile["tmp_name"], $path."/".$aFile["name"]) ;
			unlink ($path."/".$aFile["name"]) ;
			copy ($aFile["tmp_name"], $path."/".$aFile["name"]) ;
			//or die ("could not copy");
		}
		header("Location: viewimages.php");
		exit;
	}

Code: Select all

<form name="form1" method="post" action="" enctype="multipart/form-data">
<input type="hidden" name="bpress" value="">

<input type="file" name="imagefile1" class="text" />
<input type="file" name="imagefile2" class="text" />
<input type="file" name="imagefile3" class="text" />
<input type="file" name="imagefile4" class="text" />
<input type="file" name="imagefile5" class="text" />

<input type="submit" name="Submit" value="Submit" class="text" />
</form>

Posted: Mon Dec 18, 2006 2:27 pm
by feyd
hint: bpress.

Posted: Mon Dec 18, 2006 2:31 pm
by $var
i tried it like this (it was this initially, but nothing happens still):

Code: Select all

if(isset( $Submit )) 
	{ 
	$path = $_SERVER["DOCUMENT_ROOT"]."Partner_Img/";
	foreach( $_FILES as $aFile )
	{
		if ($aFile['type'] == "image/gif" || $aFile['type'] == "image/jpeg")
		{
			copy ($aFile['tmp_name'], $path."/".$aFile['name']) 
				or die ("Could not copy"); 
			echo "";
		}
	}
	header("Location: http://www.advantageboard.com/access/00 ... images.php");
	exit;
}

Posted: Mon Dec 18, 2006 2:40 pm
by feyd
You need to merge the two and fix some other bits. Here's the basic list:
  • $Submit suggests register_globals. bad
  • copy() should be move_uploaded_file(). I'm seem to remember telling you this before.. I know I've said it before to many many people.
  • copy() unlink() copy().. what's that about?
  • basename() should be used against $aFile['name'].
  • header() redirection should always, without exception, be a full URL.

Posted: Mon Dec 18, 2006 2:51 pm
by $var
i'll muck around and see what i can do.
i don't recall you telling me about move_uploaded_file() ... hopefully this will solve my problems anyhow.

i don't get why it will work in a subfolder, but not here.
thank you.

Posted: Tue Dec 19, 2006 7:59 am
by $var
Hi feyd,

I think that it must be that when I switched the servers, my new one doesn't have register_globals on.
So, I swapped $Submit for bpress and it worked, I also:
- changed the copy(); to move_uploaded_files();
- removed the unlink(); but I remember that I put it in there to overwrite the previous file... so i might put it back in.
- gave header(); a proper URL

I don't really know what you mean by 'used against'...
is that just running the file through basename($aFile['name']);?

It's working now!

Posted: Tue Dec 19, 2006 8:03 am
by feyd
$var wrote:is that just running the file through basename($aFile['name']);?
Yes, that's exactly what it means.