Solved

Upload Problem

Posted on 2003-11-08
8
316 Views
Last Modified: 2008-03-10
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."_".removebadchars($picture_name);
 if (!@copy($picture,"~tempt/pictures/".$newpicname)) { echo ("<br><blockquote>'$newpicname' '$err_msg' <br></blockquote>\n");$badupload=1; }
 else {

if ($nogd != 1 && ($gif != 1 || ($gif ==1 && $nogdgif !=1))) {
 #generate thumbnail
include("class.img2thumb.php");
$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;$bgblue=255;
      
$neu = new Img2Thumb($filename,$thumbsizew,$thumbsizeh,$fileout,$maxsize,$bgred,$bggreen,$bgblue);
$neu = new Img2Thumb($filename,$midsizew,$midsizeh,$mfileout,0,$bgred,$bggreen,$bgblue);

if ((isset($maxw) && isset($maxh)) && ($imagesize[0] > $maxw || $imagesize[1] > $maxh)) $neu = new Img2Thumb($filename,$maxw,$maxh,$filename,0,$bgred,$bggreen,$bgblue);

}
 }

 $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,type,rdate,status,resize) values('$auth','$url','$description','$type','".strtotime(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[picture]);
@unlink("pictures/t_".$d[picture]);
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.php" method="post" enctype="multipart/form-data" 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 &gt;&gt; <?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</font></td>
      <td><font size="2" face="Arial, Helvetica, sans-serif">
        <textarea name="description" cols="60" rows="4" wrap="VIRTUAL" id="description"></textarea>
        </font></td>
    </tr>
    <tr bgcolor="#f0f0f0">
      <td><font size="2" face="Arial, Helvetica, sans-serif">Type</font></td>
      <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</option>
        </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\">upgrade your membership</a>";

$r=q("select * from pictures where member='$auth'");
if (!e($r)) while ($pic=f($r))
{?>
<form action="manage_pictures.php" method="post" enctype="multipart/form-data" 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 &gt;&gt;</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</font></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></td>
      <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</option>
          <option value="Private" <?php if ($pic[type]=="Private") echo "selected";?>>Private</option>
        </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_pictures.php?picid=<?php echo $pic[id];?>&delete=1&picname=<?php echo $pic[picture];?>'">
        </div></td>
    </tr>
  </table>
</form>
<?}else echo "<br><center> No pictures uploaded. </center>";
include("themes/$theme/_footer.php");
?>


----------------------------------------------------------------



Any help would greatly be appreciated!

Julia
0
Comment
Question by:John Account
8 Comments
 
LVL 13

Expert Comment

by:lozloz
ID: 9709693
unfortunately there's no one variable holding the folder name so you'll have to change it in a few places:

 if (!@copy($picture,"~tempt/pictures/".$newpicname)) { echo ("<br><blockquote>'$newpicname' '$err_msg' <br></blockquote>\n");$badupload=1; }

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[picture]);
@unlink("pictures/t_".$d[picture]);

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
0
 
LVL 2

Expert Comment

by:webcs
ID: 9710760
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.
0
 

Author Comment

by:John Account
ID: 9710804

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

0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:John Account
ID: 9710826
ok, these lines, do change the directory loz,

 if (!@copy($picture,"~tempt/pictures/".$newpicname)) { echo ("<br><blockquote>'$newpicname' '$err_msg' <br></blockquote>\n");$badupload=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.
0
 
LVL 13

Expert Comment

by:lozloz
ID: 9710843
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/".$newpicname; etc.

loz
0
 

Author Comment

by:John Account
ID: 9711209
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
0
 

Accepted Solution

by:
CetusMOD earned 0 total points
ID: 12057535
Closed, 500 points refunded.
CetusMOD
Community Support Moderator
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now