SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Nov 2005
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation Failed to open stream error - please help

    On our new testing site we keep gettin the following error when trying to upload a photo through the form in the file addphoto.php :

    Warning: copy(Array): failed to open stream: No such file or directory in /home/bestgayd/public_html/testserv/addphoto.php on line 23

    Warning: Cannot modify header information - headers already sent by (output started at /home/bestgayd/public_html/testserv/addphoto.php:23) in /home/bestgayd/public_html/testserv/addphoto.php on line 42

    The code is just below:

    <?
    include("cookie.php");
    include("connect.php");

    if($Error1==1)
    $Error="Size of photo can not be more than 400kb";
    if($submit)
    {
    if($photo=="" || $quote=="")
    {
    $Error="Incomplete Information";
    }
    else
    {
    if($photo_size<=409600)
    {
    $resmaxid=mysql_query("select max(id) from photo");
    $rowmaxid=mysql_fetch_row($resmaxid);
    $maxid=$rowmaxid[0];
    $PHOTOIMAGE="/home/bestgayd/testserv/photoimage";
    $path=$PHOTOIMAGE.$maxid.$photo_name;
    $photoname=$maxid.$photo_name;
    copy($photo,$path);
    if($fromwhere==1)
    {
    $photoquery="insert into photo(photo,quote,username,main) values('$photoname','$quote','$UsErCoOkIe','Y')";
    }
    else
    {
    $photoquery="insert into photo(photo,quote,username,main) values('$photoname','$quote','$UsErCoOkIe','$maxid')";
    }
    $photoresult=mysql_query($photoquery,$db);
    }
    else
    {
    $Error="Size of photo can not be more than 400kb";
    }
    }
    }
    if($photoresult)
    {
    header("Location:message.php?11");
    }
    $sql="select * from users where identity='$UsErCoOkIe'";
    $result=mysql_query($sql,$db);
    $row7=mysql_fetch_array($result);
    $id=$row7["userid"];
    ?>



    Any help would be REALLY appreciated

    Thanks guys

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,156
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)

    errors

    Hi mcisbackuk, welcome to the forums,
    the first error is in this line
    copy($photo,$path);
    I would guess that the value of $photo is supposed to come from an include file, but isn't.
    the second error
    Cannot modify header information - headers already sent
    is because
    There can be NO output before the header call
    This includes white-space
    <?
    include("cookie.php");
    include("connect.php");

    line 4 outputs white-space

  3. #3
    SitePoint Member
    Join Date
    Nov 2005
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    im very new to php, and i dont quite understand that lol
    I "think" the $photo comes from the filename in the form where you browse for the file on the client machine.

    Is there any way I can change bits of this script to get it to upload to the photoimage folder in /testserv/ ? This is causing a real headache I've tried a few things but to no avail, as I say I am pretty new to php

  4. #4
    SitePoint Member
    Join Date
    Nov 2005
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also, what should be in the place of $photo on the copy line? Is it possible to change the form so the output of the browse function creates $photo, would that work or would it copy the whole thing ie "C:/Documents and Settings/" etc?

    Thanks VERY much for your help

  5. #5
    SitePoint Member
    Join Date
    Nov 2005
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is the contents of the entire file, it would probably help more:

    <?
    include("cookie.php");
    include("connect.php");
    if($Error1==1)
    $Error="Size of photo can not be more than 250kb";
    if($submit)
    {
    if($photo=="" || $quote=="")
    {
    $Error="Incomplete Information";
    }
    else
    {
    if($photo_size<=256000)
    {
    $resmaxid=mysql_query("select max(id) from photo");
    $rowmaxid=mysql_fetch_row($resmaxid);
    $maxid=$rowmaxid[0];
    $PHOTOIMAGE="/home/bestgayd/testserv/photoimage/";
    $path=$PHOTOIMAGE.$maxid.$photo_name;
    $photoname=$maxid.$photo_name;
    copy($photo,$path);
    if($fromwhere==1)
    {
    $photoquery="insert into photo(photo,quote,username,main) values('$photoname','$quote','$UsErCoOkIe','Y')";
    }
    else
    {
    $photoquery="insert into photo(photo,quote,username,main) values('$photoname','$quote','$UsErCoOkIe','$maxid')";
    }
    $photoresult=mysql_query($photoquery,$db);
    }
    else
    {
    $Error="Size of photo can not be more than 250kb";
    }
    }
    }
    if($photoresult)
    {
    header("Location:message.php?11");
    }
    $sql="select * from users where identity='$UsErCoOkIe'";
    $result=mysql_query($sql,$db);
    $row7=mysql_fetch_array($result);
    $id=$row7["userid"];
    ?>
    <html>
    <head>
    <title>Welcome to <?echo $SITE_NAME?></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <link rel="stylesheet" href="datingsite.css" type="text/css">
    </head>

    <body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onLoad="MM_preloadImages('images/arrow1.jpg')">
    <table width="778" border="0" cellspacing="0" cellpadding="0" align="center">
    <tr>
    <td valign="top" height="10"><?include("top.php");?></td>
    </tr>
    <tr>
    <td valign="top">
    <table width="100%" border="0" cellspacing="0" cellpadding="0" height="100%">
    <tr>
    <td width="19%" class="left_bg" valign="top">
    <?if($UsErCoOkIe)
    include("leftlogin.php");
    else
    include("left.php");?>
    </td>
    <td width="81%" valign="top">
    <table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
    <tr>
    <td>
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td>&nbsp;</td>
    </tr>
    </table>
    </td>
    </tr>
    <tr>
    <td class="normal_txt"> <img src="images/add_photo1.jpg" alt="add photo" width="86" height="13">
    <div align="center">
    <font size="2" color="#FF0000"><b>
    <?echo $Error."<br>";
    $Error1="";?>
    </b></font> </div>
    </td>
    </tr>
    <tr>
    <td valign="top" class="small_txt">
    <table width="98%" border="0" align="center">
    <tr>
    <td class="normal_txt">
    <b>&nbsp;&nbsp;Content Guidelines</b>
    <ul>
    <li>Each photo size must not be more than 250kb.
    <li><b>Select the photo which you want to show in your
    profile. </b>
    <li>Photos will only be shown with your profile once
    passed by our administrator.
    <li>Please note that you must appear in each of the
    photos - we will not post photos of children or pets
    only, etc.
    <li>Photos of cartoon characters or celebrities are
    copyrighted and cannot be posted.
    <li>Nudity, obscenity, sexual or otherwise offensive
    photos will not be posted. <BR>
    <?$rpic=mysql_query("select * from photo where username='$UsErCoOkIe'",$db);
    $rowpic=mysql_fetch_object($rpic);
    ?>
    </ul>
    <br>
    </td>
    </tr>
    </table></td>
    </tr>
    <tr>
    <td valign="top" class="small_txt">
    <?if($tot<5){?>
    <FORM method="post" name=form1 action="#" enctype="multipart/form-data">

    <TABLE border=0 class=dark_border width="98%" align="center">
    <TBODY>
    <TR class="small_txt">
    <TD class="small_txt" width="17%">&nbsp;</TD>
    <TD width="83%"> In the following form, please click the
    "browse" button to browse your computer's hard drive,
    and select the photo you wish to upload.
    </TD>
    </TR>
    <tr>
    <TD class="big_txt" width="17%">Your Photo/TD>
    <TD width="83%"> <input name=photo type="file" onKeyDown="return false" oncontextmenu="return false" onKeyPress="return false" onChange="very.src=photo.value;"></TD>
    </tr>
    <TR class="small_txt">
    <TD class="small_txt" width="17%">&nbsp;</TD>
    <TD width="83%"><br>
    Provide a brief description of the photo's
    location or event.<br>
    For photos with more than one person, indicate which
    one you are. </TD>
    </TR>
    <TR class="small_txt">
    <TD class="big_txt" width="17%">Your Quote/TD>
    <TD width="83%">
    <INPUT maxLength=48 name=quote value="<? echo $quote?>" size="50">
    </TD>
    </TR>
    <?
    if(eregi("register.php",$HTTP_REFERER))
    echo "<input type=hidden name=fromwhere value=1>";
    ?>


    <TR>
    <TD colSpan=2><br>
    &nbsp;&nbsp;&nbsp;&nbsp;

    <input type=submit disabled="true" name="submit" onclick="very.src=photo.value;" value="Upload Photo and Quote">


    &nbsp;&nbsp;-&nbsp;&nbsp;
    <INPUT type=reset value="Clear Form">
    <img src="images/arrowright.gif" width="1" height="1" onerror="submit.disabled='true';" alt="Loading..." name="very" onload="submit.disabled='';">

    </TD>
    </TR>
    </TBODY>
    </TABLE>
    </FORM>
    <?}?>
    </td>
    </tr>
    </table>
    </td>
    </tr>
    </table>
    </td>
    </tr>
    <tr>
    <td valign="top" class="footer_bg" height="10">
    <?include("footer.php");?>
    </td>
    </tr>
    </table>
    </body>
    </html>

    Thanks again

  6. #6
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,156
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)

    image file upload scripts

    I see the code now has the white-space/header problem fixed, 1 down As to the copy function, I'm not sure that should be used for image uploading. There are several threads in the forums dealing with various image uploading script problems, but the ones that I've seen didn't use the copy function. I would try getting a script like the one here (or one of many others that can be found online) to work and then modify your code to incorporate it. Also, you could look at these:
    http://us2.php.net/manual/en/ref.filesystem.php
    http://us3.php.net/features.file-upload
    From http://www.htmlgoodies.com/beyond/we...le.php/3560181 - page 1
    PHP Code:
    <?
    //print_r($_POST);

    if($_POST["action"] == "Upload Image")
    {
    unset(
    $imagename);

    if(!isset(
    $_FILES) && isset($HTTP_POST_FILES))
    $_FILES $HTTP_POST_FILES;

    if(!isset(
    $_FILES['image_file']))
    $error["image_file"] = "An image was not found.";


    $imagename basename($_FILES['image_file']['name']);
    //echo $imagename;

    if(empty($imagename))
    $error["imagename"] = "The name of the image was not found.";

    if(empty(
    $error))
    {
    $newimage "images/" $imagename;
    //echo $newimage;
    $result = @move_uploaded_file($_FILES['image_file']['tmp_name'], $newimage);
    if(empty(
    $result))
    $error["result"] = "There was an error moving the uploaded file.";
    }

    }

    ?>


    <form method="POST" enctype="multipart/form-data" name="image_upload_form" action="<?$_SERVER["PHP_SELF"];?>">
    <p><input type="file" name="image_file" size="20"></p>
    <p><input type="submit" value="Upload Image" name="action"></p>
    </form>

    <?
    if(is_array($error))
    {
    while(list(
    $key$val) = each($error))
    {
    echo 
    $val;
    echo 
    "<br>\n";
    }
    }
    ?>
    Note that the folder specified in the line
    $newimage = "images/" . $imagename;
    must have write permissions

  7. #7
    SitePoint Member
    Join Date
    Nov 2005
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think I have finally sorted the problem, thanks to your recommendations, again thanks ever so much, this has been one headache sorted!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •