John Account
asked on
Upload Problem
ok, I have a script, which uploads a file to a folder called "pictures" Now, I want that file to be uploaded to a folder called "pictures", but on a nother server. Think is, I can't find where that path is set. I've looked in my code over and over and didn't find an upload function or a path for the upload. This code was purchased, I didn't write it and I'm still not an expert at php, so I would need help. Here is the code.
-------------------------- ---------- ---------- ------
<?php
include("member.php");
$badupload =0;
if (isset($upload))
{
if (!$url || $allowurl == 0)
{
$imagesize = @getimagesize($picture);
switch ( $imagesize[2] ) {
case 1:
$gif=1;
break;
case 2:
$jpg = 1;
break;
case 3:
break;
default:
$err_msg = "Not a valid image upload. .JPG .GIF and .PNG formats are accepted only.";
@unlink($picture);
$badupload=1;
break;
}
if (($uploadsize > 20) && (filesize($picture) > ($uploadsize * 1024))) {
$err_msg="Filesize too big. Maximum filesize allowed is $uploadsize K";
@unlink($picture); $badupload=1;
}
$newpicname = "m".$auth."_".removebadcha rs($pictur e_name);
if (!@copy($picture,"~tempt/p ictures/". $newpicnam e)) { echo ("<br><blockquote>'$newpic name' '$err_msg' <br></blockquote>\n");$bad upload=1; }
else {
if ($nogd != 1 && ($gif != 1 || ($gif ==1 && $nogdgif !=1))) {
#generate thumbnail
include("class.img2thumb.p hp");
$filename = "pictures/".$newpicname;
$fileout = "pictures/t_".$newpicname;
$mfileout = "pictures/m_".$newpicname;
if (!isset($thumbsizew)) $thumbsizew=60;
if (!isset($thumbsizeh)) $thumbsizeh=60;
if (!isset($midsizew)) $midsizew=300;
if (!isset($midsizeh)) $midsizeh=250;
$maxsize=1;
$bgred=255;$bggreen=255;$b gblue=255;
$neu = new Img2Thumb($filename,$thumb sizew,$thu mbsizeh,$f ileout,$ma xsize,$bgr ed,$bggree n,$bgblue) ;
$neu = new Img2Thumb($filename,$midsi zew,$midsi zeh,$mfile out,0,$bgr ed,$bggree n,$bgblue) ;
if ((isset($maxw) && isset($maxh)) && ($imagesize[0] > $maxw || $imagesize[1] > $maxh)) $neu = new Img2Thumb($filename,$maxw, $maxh,$fil ename,0,$b gred,$bggr een,$bgblu e);
}
}
$url=$newpicname;
};
if (!e(q("select picture from pictures where picture = '$url'"))) q("delete from pictures where picture = '$url'");
if ($type=="Main" && $badupload == 0) q("update pictures set type='Public' where type='Main' and member='$auth'");
if ($type == "Public") if (e(q("select picture from pictures where type = 'Main' and member = '$auth'"))) $type ="Main";
if ($badupload ==0) q("insert into pictures (member,picture,details,ty pe,rdate,s tatus,resi ze) values('$auth','$url','$de scription' ,'$type',' ".strtotim e(date("d M Y H:i:s"))."','0','yes')");
};
if ($edit&&$picid)
{
if ($type=="Main" && $badupload == 0) q("update pictures set type='Public' where type='Main' and member='$auth'");
q("update pictures set details='$description', type='$type' where id='$picid' and member='$auth'");
};
if ($delete&&$picid)
{
$d=@f(q("select picture from pictures where id ='$picid' and member='$auth'"));
@unlink("pictures/".$d[pic ture]);
@unlink("pictures/t_".$d[p icture]);
q("delete from pictures where id='$picid' and member='$auth'");
};
if (e(q("select picture from pictures where member='$auth' and type='Main'") ) && !e(q("select picture from pictures where member='$auth' and type='Public'"))) q("update pictures set type='Main' where member='$auth' and type='Public' LIMIT 1");
$tpic=f(q("select count(*) as nr from pictures where member='$auth'"));
if ($tpic[nr]<$mem_pics)
{?>
<form action="manage_pictures.ph p" method="post" enctype="multipart/form-da ta" name="form1">
<table width="600" border="0" cellpadding="2" cellspacing="1" align="center">
<tr bgcolor="#FFFFFF">
<td colspan="2"><font size="2" face="Arial, Helvetica, sans-serif"><strong>Add
new picture >> <?php echo "($tpic[nr]/$mem_pics)";?> </strong>< /font></td >
</tr>
<tr>
<td height="3" colspan="2" bgcolor="#000000"> </td>
</tr>
<tr bgcolor="#f0f0f0">
<td><font size="2" face="Arial, Helvetica, sans-serif">Upload Picture</font></td>
<td><font size="2" face="Arial, Helvetica, sans-serif">
<input name="picture" type="file" id="picture" size="60">
</font></td>
<? if ($allowurl == 1) { ?>
<TR bgcolor="#f0f0f0" class='tr1'>
<TD>Or display from url</TD>
<TD><input name="url" type="text" id="url" size="60" value=""></TD>
</TR>
<? } ?>
<tr bgcolor="#f0f0f0">
<td><font size="2" face="Arial, Helvetica, sans-serif">Description</f ont></td>
<td><font size="2" face="Arial, Helvetica, sans-serif">
<textarea name="description" cols="60" rows="4" wrap="VIRTUAL" id="description"></textare a>
</font></td>
</tr>
<tr bgcolor="#f0f0f0">
<td><font size="2" face="Arial, Helvetica, sans-serif">Type</font></t d>
<td><font size="2" face="Arial, Helvetica, sans-serif">
<select name="type" id="type">
<option value="Main">Main</option>
<option value="Public" selected>Public</option>
<option value="Private">Private</o ption>
</select>
</font></td>
</tr>
<tr bgcolor="#f0f0f0">
<td colspan="2"><div align="center">
<input name="upload" type="hidden" id="upload" value="1">
<input type="reset" name="Submit2" value="Reset">
<input type="submit" name="Submit" value="Upload">
</div></td>
</tr>
</table>
</form><?php
}else echo "Your can have up to $mem_pics pictures on your account. To add another picture, you must remove one or <a href=\"meminfo.php\">upgra de your membership</a>";
$r=q("select * from pictures where member='$auth'");
if (!e($r)) while ($pic=f($r))
{?>
<form action="manage_pictures.ph p" method="post" enctype="multipart/form-da ta" name="form1">
<table width="600" border="0" cellpadding="2" cellspacing="1" align="center">
<tr bgcolor="#FFFFFF">
<td colspan="2"><font size="2" face="Arial, Helvetica, sans-serif"><strong>Edit
picture details >></strong><em> </em></font></td>
</tr>
<tr>
<td height="3" colspan="2" bgcolor="#000000"> </td>
</tr>
<tr bgcolor="#f0f0f0">
<td colspan="2"><div align="center"><a target='picture' href=http://www.whispersoftemptation.com/pictures/<?php echo ($pic[picture]); ?>'><IMG SRC=http://www.whispersoftemptation.com/pictures/<?php echo ($pic[picture]); ?> width='300' border=1 alt='Full size!'></A></div></td>
</tr>
<tr bgcolor="#f0f0f0">
<td><font size="2" face="Arial, Helvetica, sans-serif">Description</f ont></td>
<td><font size="2" face="Arial, Helvetica, sans-serif">
<textarea name="description" cols="60" rows="3" wrap="VIRTUAL" id="description"><?php echo $pic[details]; ?></textarea>
</font></td>
</tr>
<tr bgcolor="#f0f0f0">
<td><font size="2" face="Arial, Helvetica, sans-serif">Type</font></t d>
<td><font size="2" face="Arial, Helvetica, sans-serif">
<select name="type" id="type">
<option value="Main" <?php if ($pic[type]=="Main") echo "selected";?>>Main</option >
<option value="Public" <?php if ($pic[type]=="Public") echo "selected";?>>Public</opti on>
<option value="Private" <?php if ($pic[type]=="Private") echo "selected";?>>Private</opt ion>
</select> Private images will be viewable only by members you approve.
</font></td>
</tr>
<tr bgcolor="#f0f0f0">
<td><font size="2" face="Arial, Helvetica, sans-serif">Current Status</font></td>
<td><font size="2" face="Arial, Helvetica, sans-serif">
<? if ($pic[status] ==1) echo "Validated for public or private use";
elseif ($pic[status] ==0 && ($pic[type] == "Public" || $pic[type] =="Main")) echo "Pending validation by site moderators for public display";
elseif ($pic[status] ==0 || $pic[status] == 2) echo "Ok for private display";
?>
</font></td>
</tr>
<tr bgcolor="#f0f0f0">
<td colspan="2"><div align="center">
<input name="edit" type="hidden" id="edit" value="1">
<input name="picid" type="hidden" id="picid" value="<?php echo $pic[id];?>">
<input type="reset" name="Submit22" value="Reset">
<input type="submit" name="Submit3" value="Save Changes">
<input type="button" name="Submit222" value="Delete Picture" onclick="document.location ='manage_p ictures.ph p?picid=<? php echo $pic[id];?>&delete=1&picna me=<?php echo $pic[picture];?>'">
</div></td>
</tr>
</table>
</form>
<?}else echo "<br><center> No pictures uploaded. </center>";
include("themes/$theme/_fo oter.php") ;
?>
-------------------------- ---------- ---------- ---------- --------
Any help would greatly be appreciated!
Julia
--------------------------
<?php
include("member.php");
$badupload =0;
if (isset($upload))
{
if (!$url || $allowurl == 0)
{
$imagesize = @getimagesize($picture);
switch ( $imagesize[2] ) {
case 1:
$gif=1;
break;
case 2:
$jpg = 1;
break;
case 3:
break;
default:
$err_msg = "Not a valid image upload. .JPG .GIF and .PNG formats are accepted only.";
@unlink($picture);
$badupload=1;
break;
}
if (($uploadsize > 20) && (filesize($picture) > ($uploadsize * 1024))) {
$err_msg="Filesize too big. Maximum filesize allowed is $uploadsize K";
@unlink($picture); $badupload=1;
}
$newpicname = "m".$auth."_".removebadcha
if (!@copy($picture,"~tempt/p
else {
if ($nogd != 1 && ($gif != 1 || ($gif ==1 && $nogdgif !=1))) {
#generate thumbnail
include("class.img2thumb.p
$filename = "pictures/".$newpicname;
$fileout = "pictures/t_".$newpicname;
$mfileout = "pictures/m_".$newpicname;
if (!isset($thumbsizew)) $thumbsizew=60;
if (!isset($thumbsizeh)) $thumbsizeh=60;
if (!isset($midsizew)) $midsizew=300;
if (!isset($midsizeh)) $midsizeh=250;
$maxsize=1;
$bgred=255;$bggreen=255;$b
$neu = new Img2Thumb($filename,$thumb
$neu = new Img2Thumb($filename,$midsi
if ((isset($maxw) && isset($maxh)) && ($imagesize[0] > $maxw || $imagesize[1] > $maxh)) $neu = new Img2Thumb($filename,$maxw,
}
}
$url=$newpicname;
};
if (!e(q("select picture from pictures where picture = '$url'"))) q("delete from pictures where picture = '$url'");
if ($type=="Main" && $badupload == 0) q("update pictures set type='Public' where type='Main' and member='$auth'");
if ($type == "Public") if (e(q("select picture from pictures where type = 'Main' and member = '$auth'"))) $type ="Main";
if ($badupload ==0) q("insert into pictures (member,picture,details,ty
};
if ($edit&&$picid)
{
if ($type=="Main" && $badupload == 0) q("update pictures set type='Public' where type='Main' and member='$auth'");
q("update pictures set details='$description', type='$type' where id='$picid' and member='$auth'");
};
if ($delete&&$picid)
{
$d=@f(q("select picture from pictures where id ='$picid' and member='$auth'"));
@unlink("pictures/".$d[pic
@unlink("pictures/t_".$d[p
q("delete from pictures where id='$picid' and member='$auth'");
};
if (e(q("select picture from pictures where member='$auth' and type='Main'") ) && !e(q("select picture from pictures where member='$auth' and type='Public'"))) q("update pictures set type='Main' where member='$auth' and type='Public' LIMIT 1");
$tpic=f(q("select count(*) as nr from pictures where member='$auth'"));
if ($tpic[nr]<$mem_pics)
{?>
<form action="manage_pictures.ph
<table width="600" border="0" cellpadding="2" cellspacing="1" align="center">
<tr bgcolor="#FFFFFF">
<td colspan="2"><font size="2" face="Arial, Helvetica, sans-serif"><strong>Add
new picture >> <?php echo "($tpic[nr]/$mem_pics)";?>
</tr>
<tr>
<td height="3" colspan="2" bgcolor="#000000"> </td>
</tr>
<tr bgcolor="#f0f0f0">
<td><font size="2" face="Arial, Helvetica, sans-serif">Upload Picture</font></td>
<td><font size="2" face="Arial, Helvetica, sans-serif">
<input name="picture" type="file" id="picture" size="60">
</font></td>
<? if ($allowurl == 1) { ?>
<TR bgcolor="#f0f0f0" class='tr1'>
<TD>Or display from url</TD>
<TD><input name="url" type="text" id="url" size="60" value=""></TD>
</TR>
<? } ?>
<tr bgcolor="#f0f0f0">
<td><font size="2" face="Arial, Helvetica, sans-serif">Description</f
<td><font size="2" face="Arial, Helvetica, sans-serif">
<textarea name="description" cols="60" rows="4" wrap="VIRTUAL" id="description"></textare
</font></td>
</tr>
<tr bgcolor="#f0f0f0">
<td><font size="2" face="Arial, Helvetica, sans-serif">Type</font></t
<td><font size="2" face="Arial, Helvetica, sans-serif">
<select name="type" id="type">
<option value="Main">Main</option>
<option value="Public" selected>Public</option>
<option value="Private">Private</o
</select>
</font></td>
</tr>
<tr bgcolor="#f0f0f0">
<td colspan="2"><div align="center">
<input name="upload" type="hidden" id="upload" value="1">
<input type="reset" name="Submit2" value="Reset">
<input type="submit" name="Submit" value="Upload">
</div></td>
</tr>
</table>
</form><?php
}else echo "Your can have up to $mem_pics pictures on your account. To add another picture, you must remove one or <a href=\"meminfo.php\">upgra
$r=q("select * from pictures where member='$auth'");
if (!e($r)) while ($pic=f($r))
{?>
<form action="manage_pictures.ph
<table width="600" border="0" cellpadding="2" cellspacing="1" align="center">
<tr bgcolor="#FFFFFF">
<td colspan="2"><font size="2" face="Arial, Helvetica, sans-serif"><strong>Edit
picture details >></strong><em> </em></font></td>
</tr>
<tr>
<td height="3" colspan="2" bgcolor="#000000"> </td>
</tr>
<tr bgcolor="#f0f0f0">
<td colspan="2"><div align="center"><a target='picture' href=http://www.whispersoftemptation.com/pictures/<?php echo ($pic[picture]); ?>'><IMG SRC=http://www.whispersoftemptation.com/pictures/<?php echo ($pic[picture]); ?> width='300' border=1 alt='Full size!'></A></div></td>
</tr>
<tr bgcolor="#f0f0f0">
<td><font size="2" face="Arial, Helvetica, sans-serif">Description</f
<td><font size="2" face="Arial, Helvetica, sans-serif">
<textarea name="description" cols="60" rows="3" wrap="VIRTUAL" id="description"><?php echo $pic[details]; ?></textarea>
</font></td>
</tr>
<tr bgcolor="#f0f0f0">
<td><font size="2" face="Arial, Helvetica, sans-serif">Type</font></t
<td><font size="2" face="Arial, Helvetica, sans-serif">
<select name="type" id="type">
<option value="Main" <?php if ($pic[type]=="Main") echo "selected";?>>Main</option
<option value="Public" <?php if ($pic[type]=="Public") echo "selected";?>>Public</opti
<option value="Private" <?php if ($pic[type]=="Private") echo "selected";?>>Private</opt
</select> Private images will be viewable only by members you approve.
</font></td>
</tr>
<tr bgcolor="#f0f0f0">
<td><font size="2" face="Arial, Helvetica, sans-serif">Current Status</font></td>
<td><font size="2" face="Arial, Helvetica, sans-serif">
<? if ($pic[status] ==1) echo "Validated for public or private use";
elseif ($pic[status] ==0 && ($pic[type] == "Public" || $pic[type] =="Main")) echo "Pending validation by site moderators for public display";
elseif ($pic[status] ==0 || $pic[status] == 2) echo "Ok for private display";
?>
</font></td>
</tr>
<tr bgcolor="#f0f0f0">
<td colspan="2"><div align="center">
<input name="edit" type="hidden" id="edit" value="1">
<input name="picid" type="hidden" id="picid" value="<?php echo $pic[id];?>">
<input type="reset" name="Submit22" value="Reset">
<input type="submit" name="Submit3" value="Save Changes">
<input type="button" name="Submit222" value="Delete Picture" onclick="document.location
</div></td>
</tr>
</table>
</form>
<?}else echo "<br><center> No pictures uploaded. </center>";
include("themes/$theme/_fo
?>
--------------------------
Any help would greatly be appreciated!
Julia
I think the answer to your question here is there is not an answer. I do not see anything in your code that connects you to another server nor would changing a PATH allow you to access another server.
PATHS will just manipulate your native server.
PATHS will just manipulate your native server.
ASKER
Ok, I'll try to explain a little more...
I have many web sites, all sharing the same database on one server. The same code is on every site, which are on the same server, but in different hosting packages. I need to upload these pictures to the same folder in order for the pictures to be viewable from any of the sites. If I can't do it with this script, is it something that is possible to achieve or is it simply an exercise in futility?
I'll try changing the lines you pointed out, loz, but I already tried and it didnt' work... I'll nonetheless try it again.
thanks again
Julia
ASKER
ok, these lines, do change the directory loz,
if (!@copy($picture,"~tempt/p ictures/". $newpicnam e)) { echo ("<br><blockquote>'$newpic name' '$err_msg' <br></blockquote>\n");$bad upload=1; }
$filename = "pictures/".$newpicname;
$fileout = "pictures/t_".$newpicname;
$mfileout = "pictures/m_".$newpicname;
but everytime I try to change it, I get an error message. I'm not quite sure what the syntax would be if I wanted to set it to another server. I'm sure I wouldn't type the "http://mydomain.com/picture" right? So what would I put? What would you put?
Julia again.
if (!@copy($picture,"~tempt/p
$filename = "pictures/".$newpicname;
$fileout = "pictures/t_".$newpicname;
$mfileout = "pictures/m_".$newpicname;
but everytime I try to change it, I get an error message. I'm not quite sure what the syntax would be if I wanted to set it to another server. I'm sure I wouldn't type the "http://mydomain.com/picture" right? So what would I put? What would you put?
Julia again.
as i said earlier, you can't copy files onto a remote server so you'd have to have the script on each domain, allowing you to reference the folder by its relative location to the script. so if i had the the pictures in the URLs: http://mydomain.com/pictures and http://myserver.com/images/photos, i'd have one script with the folder names as you have them, and one with images/photos/".$newpicnam e; etc.
loz
loz
ASKER
you know what? I am so dumb! I just have to load the upload page from the main server instead of my local one. Like that, It will upload to that picture folder... Sorry to have taken your time!
Julia
Julia
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
if (!@copy($picture,"~tempt/p
second part of that copy function contains the file location
$filename = "pictures/".$newpicname;
$fileout = "pictures/t_".$newpicname;
$mfileout = "pictures/m_".$newpicname;
the above code is to do with thumbnail generation so you'll need to change the folder there as well i suppose
@unlink("pictures/".$d[pic
@unlink("pictures/t_".$d[p
the above code is for removing files and the directory may need to be changed
the thing i don't understand is why you would need to change the directory information when its the same directory name but on a different server, unless you're storing the upload script on one server and trying to copy the files to another server. if this is the case, i don't think it'll be possible to copy the files there.. anyway if you need more help then leave a message
loz