SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Addict
    Join Date
    Mar 2003
    Location
    Greenville, SC
    Posts
    388
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    file not uploading.

    hello,

    I'm trying to upload a file, but I'm getting the following error:

    Warning: copy(): open_basedir restriction in effect. File(/var/www/html/news/images/newsattach/tutbutton2.gif) is not within the allowed path(s): (/home/virtual/site180/fst:/home/virtual/zerooneproductions.net:/tmp) in /home/virtual/site180/fst/var/www/html/news/ashprojects/ashnews.php on line 245

    Warning: copy(/var/www/html/news/images/newsattach/tutbutton2.gif): failed to open stream: Operation not permitted in /home/virtual/site180/fst/var/www/html/news/ashprojects/ashnews.php on line 245

    Attachment NOT uploaded

    can someone tell me what a "open_basedir restriction is??

  2. #2
    Formerly known as RockNRollPig Shpigford's Avatar
    Join Date
    Dec 2002
    Location
    Denver, CO
    Posts
    2,877
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you have the correct permissions set on the file and/or directory?

  3. #3
    SitePoint Zealot anchorwave's Avatar
    Join Date
    Nov 2003
    Location
    Tucson, Arizona
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    open_basedir restriction means that you can't specify the full path to a file when refering to a file location.

    Instead of writing to: /var/www/html/news/images/newsattach/tutbutton2.gif
    write to "images/newsattach/tutbutton2.gif".

    This is happening because of a setting that your host has setup in php.ini. It prevents you from calling the full path to any file. In theory it is supposed to prevent you from altering files on the server that have vunerable permissions that are not in your hosting directory.

    Give it a shot, also make sure that the "images" directory has proper permissions.

  4. #4
    SitePoint Zealot anchorwave's Avatar
    Join Date
    Nov 2003
    Location
    Tucson, Arizona
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ps. here is a tip for the future...

    when programming make always try to use relative paths instead of absolute paths.

    Like
    include('includes/dbconnection.inc.php');
    instead of
    include('/home/sites/www.domain.com/web/includes/dbconnection.inc.php');

    This will make your code easily movable. I just moved about 30 sites to a new server that were programed with absolute paths and the server had the open_basedir restriction turned on. It was a pain in the ***.

    Good luck

  5. #5
    SitePoint Addict
    Join Date
    Mar 2003
    Location
    Greenville, SC
    Posts
    388
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    now I'm getting the following error:

    Warning: copy(news/images/newsattach/creating_shapes.gif): failed to open stream: No such file or directory in /home/virtual/site180/fst/var/www/html/news/ashprojects/ashnews.php on line 245

    Attachment NOT uploaded

  6. #6
    SitePoint Zealot anchorwave's Avatar
    Join Date
    Nov 2003
    Location
    Tucson, Arizona
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this error probably means that it could not find your creating_shapes.gif file to copy. Post some of your code.

  7. #7
    SitePoint Addict
    Join Date
    Mar 2003
    Location
    Greenville, SC
    Posts
    388
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok here you go:

    the form:
    Code:
    <form method=post action=<?php echo("$PHP_SELF"); ?> name="post" enctype="multipart/form-data">
    		            <table cellpadding="3" cellspacing="2" border="0">
                          <tr> 
                            <td colspan="2" class="title">Add News Item</td>
                          </tr>
                          <tr> 
                            <td class=admin width="100">Username</td>
                            <td class=admin2> 
                              <?php echo("$thisusername"); ?>
                            </td>
                          </tr>
                          <tr> 
                            <td class=admin width="100">Category:</td>
                            <td class=admin2> 
                              <?php echo("$catname"); ?>
                            </td>
                          </tr>
                          <tr> 
                            <td class=admin width="100">Title:</td>
                            <td class=admin2> 
                              <input type=text name=title tabindex=1>
                            </td>
                          </tr>
                          <tr> 
                            <td class=admin valign=top width="100">Show entry:<br>
                              <br>
                              <table cellpadding=3 cellspacing=0 border=0>
                                <?php
    								$startend = 1;
    								$sql_smilies = "SELECT * FROM ashnews_smilies LIMIT 9";
    								$sql_result_smilies = mysql_query($sql_smilies, $connection) or die ("$text_noquery - 3");			
    								while($row_smilies = mysql_fetch_array($sql_result_smilies)) {
    									$code = $row_smilies['code'];
    									$filename = $row_smilies['filename'];
    									
    									$smiley = "<img src=$pathtosmilies/$filename border=0>";
    									
    									if ($startend == 1) { 
    										echo("<tr>");
    										$startend = $startend + 1; }
    									echo("<td><a href=\"javascript:emoticon('$code')\">$smiley</a></td>");
    									if ($startend == 4) {
    										echo("</tr>");
    										$startend = 1; }
    									else {
    										$startend = $startend + 1; }
    								}									
    							?>
                              </table><br>
    						  <a href="smilies.php" onclick="window.open('smilies.php', '_ashnewssmilies', 'HEIGHT=300,resizable=yes,scrollbars=yes,WIDTH=250');return false;" target="_ashnewssmilies">more smilies</a>
                            </td>
                            <td class=admin2> 
                              <table width="450" border="0" cellspacing="0" cellpadding="2">
                                <tr align="center" valign="middle"> 
                                  <td class=admin3> 
                                    <input type="button" class="button" accesskey="b" name="addbbcode0" value=" B " style="font-weight:bold; width: 30px" onClick="bbstyle(0)" onMouseOver="helpline('b')" />
                                  </td>
                                  <td class=admin3> 
                                    <input type="button" class="button" accesskey="i" name="addbbcode2" value=" i " style="font-style:italic; width: 30px" onClick="bbstyle(2)" onMouseOver="helpline('i')" />
                                  </td>
                                  <td class=admin3> 
                                    <input type="button" class="button" accesskey="u" name="addbbcode4" value=" u " style="text-decoration: underline; width: 30px" onClick="bbstyle(4)" onMouseOver="helpline('u')" />
                                  </td>
                                  <td class=admin3> 
                                    <input type="button" class="button" accesskey="q" name="addbbcode6" value="Quote" style="width: 50px" onClick="bbstyle(6)" onMouseOver="helpline('q')" />
                                  </td>
                                  <td class=admin3> 
                                    <input type="button" class="button" accesskey="c" name="addbbcode8" value="Code" style="width: 40px" onClick="bbstyle(8)" onMouseOver="helpline('c')" />
                                  </td>
                                  <td class=admin3> 
                                    <input type="button" class="button" accesskey="l" name="addbbcode10" value="List 1" style="width: 40px" onClick="bbstyle(10)" onMouseOver="helpline('l')" />
                                  </td>
                                  <td class=admin3> 
                                    <input type="button" class="button" accesskey="o" name="addbbcode12" value="List 2" style="width: 40px" onClick="bbstyle(12)" onMouseOver="helpline('o')" />
                                  </td>
                                  <td class=admin3> 
                                    <input type="button" class="button" accesskey="p" name="addbbcode14" value="Img" style="width: 40px"  onClick="bbstyle(14)" onMouseOver="helpline('p')" />
                                  </td>
                                  <td class=admin3> 
                                    <input type="button" class="button" accesskey="w" name="addbbcode16" value="URL" style="text-decoration: underline; width: 40px" onClick="bbstyle(16)" onMouseOver="helpline('w')" />
                                  </td>
                                  <td nowrap align="right" class=admin3><a href="javascript:bbstyle(-1)" class="admin3" onMouseOver="helpline('a')">Close 
                                    Tags</a></td>
                                </tr>
                                <tr> 
                                  <td colspan="10" class=admin3> 
                                    <input type="text" name="helpbox" size="45" maxlength="75" style="width:375px; font-size:10px" class="helpline" value="Tip: Styles can be applied quickly to selected text" />
                                  </td>
                                </tr>
                              </table>
                              <textarea name=text cols="50" rows="10" tabindex="3" class="post" onselect="storeCaret(this);" onclick="storeCaret(this);" onkeyup="storeCaret(this);"></textarea>
                            </td>
                          </tr>
                          <tr> 
                            <td class=admin width="100" valign="top">Rest of entry:</td>
                            <td class=admin2>
                              <textarea name=text2 cols="50" rows="10" tabindex="4" class="post" onSelect="storeCaret(this);" onClick="storeCaret(this);" onKeyUp="storeCaret(this);"></textarea>
                            </td>
                          </tr>
                          <tr> 
                            <td class=admin width="100">Allow comments:</td>
                            <td class=admin2> 
                              <input type="radio" name="allowcomment" value="1" checked>
                              Yes 
                              <input type="radio" name="allowcomment" value="0">
                              No </td>
                          </tr>
                          <tr> 
                            <td class=admin width="100">Attachment:</td>
                            <td class=admin2> 
                              <input type="file" name="attach">
                            </td>
                          </tr>
                          <tr> 
                            <td class=admin width="100">Sticky:</td>
                            <td class=admin2> 
                              <input type="radio" name="sticky" value="1">
                              Yes 
                              <input type="radio" name="sticky" value="0" checked>
                              No </td>
                          </tr>
                          <tr> 
                            <td class=admin width="100"> </td>
                            <td class=admin2> 
                              <input type="submit" name="Submit" value="Submit">
                              <input type="reset" name="Submit2" value="Reset">
                              <input type="hidden" name="page" value="doadd">
                              <input type="hidden" name="catid" value="<?php echo("$catid"); ?>">
                            </td>
                          </tr>
                        </table>
    </form>

    The action code:
    PHP Code:
    // ---------- INSERT INFO INTO DATABASE ------------
    if($page == "doadd") {

        if(
    $title != "" AND $text != "") {
            if (
    $attach_name != "") {
                if (
    $attach_size $attachfilesize) {
                    
    $filename "/$attach_name";
                    if( 
    copy($attach,$rootpathtoattach.$filename) ) {
                        echo(
    "<br>Attachment uploaded!");
                        
    $attach 1; }
                    else {
                        echo(
    "<br>Attachment NOT uploaded");
                        
    $attach 0; }
                }
                else {
                    echo(
    "<br>Attachment size too big");
                    
    $attach 0; }
            }
            else {
                
    $attach 0; }

            
    $sql "INSERT INTO ashnews_news SET catid='$catid', sticky='$sticky', postedby='$thisuserid', 
                    title='
    $title', text='$text', text2='$text2', date=NOW() + Interval $timeoffset hour, attach='$attach', attachname='$attach_name', 
                    allowcomment='
    $allowcomment' ";
            
    $sql_result mysql_query($sql$connection) or die ("$text_noquery - 4");
        
            if (!
    $sql_result) { 
                echo (
    "<p>News not inserted.</p>"); }
            else {
                echo(
    "<p>News inserted successfully! <a href=$PHP_SELF>Back to the main admin page</a>"); }
        }
        else {
            echo(
    "<p>You did not fill in all the required fields.  Please <a href=javascript:history.back(1)>go back</a> and try again.</p>"); }
    }
    // -------------------------------------------------- 
    included paths:

    PHP Code:

    // --------- FILEPATHS & FILENAMES --------- 
    global $pathtosmilies;   // DON'T EDIT!

    $pathtoashnews "http://www.zerooneproductions.net/news";    // Path to directory where ashnews (not the one in the 'ashprojects' directory) resides (No trailing slash, leave blank if it is in root directory)
    $pathtoimages "http://www.zerooneproductions.net/images";  // Path to images directory (No trailing slash)
    $rootpathtosmilies "/var/www/html/news/images/newssmilies"// Server path to smiley folder (No trailing slash)
    $pathtosmilies "http://www.zerooneproductions.net/news/images/newssmilies";  // Path to smiley directory (No trailing slash)
    $rootpathtoattach "/home/virtual/site180/fst/var/www/html/news/images/newsattach/tutbutton2.gif";  // Server path to attach folder (No trailing slash)
    $filepathtoattach "/home/virtual/site180/fst/var/www/html/news/images/newsattach";  // Path to attachment directory (No trailing slash, must be CHMOD 777 in order to upload)
    $attachfilesize "5000";  // Max file size in kb of attachments 
    I hope this makes sense.

  8. #8
    SitePoint Addict
    Join Date
    Mar 2003
    Location
    Greenville, SC
    Posts
    388
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have it fixed now. Thanks for all that helped:


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
  •