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
$var
Forum Contributor
Posts: 317 Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto
Post
by $var » Mon Dec 18, 2006 2:25 pm
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>
Last edited by
$var on Tue Dec 19, 2006 8:39 am, edited 1 time in total.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Dec 18, 2006 2:27 pm
hint: bpress.
$var
Forum Contributor
Posts: 317 Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto
Post
by $var » Mon Dec 18, 2006 2:31 pm
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;
}
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Mon Dec 18, 2006 2:40 pm
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.
$var
Forum Contributor
Posts: 317 Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto
Post
by $var » Mon Dec 18, 2006 2:51 pm
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.
$var
Forum Contributor
Posts: 317 Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto
Post
by $var » Tue Dec 19, 2006 7:59 am
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!
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Dec 19, 2006 8:03 am
$var wrote: is that just running the file through basename($aFile['name']);?
Yes, that's exactly what it means.