#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    37
    Rep Power
    10

    PHP Warning: move_uploaded_file(): Unable to move '/tmp/etc' to 'pictures/13.j


    I am working with a script to post some text and a resized picture to a website. The text part works fine. The picture is supposed to be uploaded, its largest dimension resized to 80pts, renamed to the story id number, and posted with the text.

    Here is the code:
    PHP Code:
    <?php
                                                                                                                                 
    include ('include_fns.php');
                                                                                                                                 
    if (isset(
    $HTTP_GET_VARS['story']))
      
    $s get_story_record($HTTP_GET_VARS['story']);
                                                                                                                                 
    ?>
                                                                                                                                 
    <form action="story_submit.php" method="post" enctype="multipart/form-data">
    <input type="hidden" name="story" value="<?php print $HTTP_GET_VARS['story'];?>">
    <input type="hidden" name="destination"
    value="<?php print $HTTP_SERVER_VARS['HTTP_REFERER'];?>">
    <table>
                                                                                                                                 
    <tr>
      <td align="center">Headline<td>
    </tr>
    <tr>
      <td><input size="80" name="headline"
                  value="<?php print $s['headline'];?>"></td>
    </tr>
                                                                                                                                 
    <tr>
      <td align="center">Page</td>
    </tr>
    <tr>
      <td align="center"><?php print query_select('page',
                 
    "select p.code, p.description
                  from pages p, writer_permissions wp, stories s
                  where p.code = wp.page
                  and wp.writer = s.writer
                  and s.id ="
    .$HTTP_GET_VARS['story'], $s['page']);?></td>
    </tr>
                                                                                                                                 
    <tr>
      <td align="center">Story text (can contain HTML tags)</td>
    </tr>
    <tr>
      <td><textarea cols="80" rows="7" name="story_text"
      </td>
    </tr>
                                                                                                                                 
    <tr>
      <td align="center">Or upload HTML file</td>
    </tr>
    <tr>
      <td align="center"><input type="file" name="html" size="40"></td>
    </tr>
                                                                                                                                 
    <tr>
      <td align="center">Picture</td>
    </tr>
    <tr>
      <td align="center"><input type="file" name="picture" size="40"></td>
    </tr>
                                                                                                                                 
    <?php
    if ($s[picture]) {
      
    $size   getImageSize($s['picture']);
      
    $width  $size[0];
      
    $height $size[1];
    ?>
    <tr>
      <td align="center">
        <img src="<?php print $s['picture'];?>"
              width="<?php print $width;?>" height="<?php print $height;?>">
      </td>
    </tr>
    <?php ?>
                                                                                                                                 
                                                                                                                                 
    <tr>
      <td align="center"><input type="submit" value="Submit"></td>
    </tr>
                                                                                                                                 
    </table>
    </form>


    Here is my error log:
    [client 69.17.65.22] PHP Notice: A session had already been started - ignoring session_start() in /var/www/html/vh09/stories.php on line 6
    [client 69.17.65.22] PHP Notice: A session had already been started - ignoring session_start() in /var/www/html/vh09/stories.php on line 6, referer: http://www.yourline-online.com/stories.php
    [client 69.17.65.22] PHP Notice: Undefined index: story in /var/www/html/vh09/story.php on line 11, referer: http://www.yourline-online.com/stories.php
    [client 69.17.65.22] PHP Notice: Undefined variable: s in /var/www/html/vh09/story.php on line 21, referer: http://www.yourline-online.com/stories.php
    [client 69.17.65.22] PHP Notice: Undefined index: story in /var/www/html/vh09/story.php on line 33, referer: http://www.yourline-online.com/stories.php
    [client 69.17.65.22] PHP Notice: Undefined variable: s in /var/www/html/vh09/story.php on line 33, referer: http://www.yourline-online.com/stories.php
    [client 69.17.65.22] PHP Notice: Undefined variable: s in /var/www/html/vh09/story.php on line 41, referer: http://www.yourline-online.com/stories.php
    [client 69.17.65.22] PHP Notice: Use of undefined constant picture - assumed 'picture' in /var/www/html/vh09/story.php on line 60, referer: http://www.yourline-online.com/stories.php
    [client 69.17.65.22] PHP Notice: Undefined variable: s in /var/www/html/vh09/story.php on line 60, referer: http://www.yourline-online.com/stories.php
    [client 69.17.65.22] PHP Notice: Undefined index: page in /var/www/html/vh09/story_submit.php on line 11, referer: http://www.yourline-online.com/story.php
    [client 69.17.65.22] PHP Warning: move_uploaded_file(pictures/13.jpg): failed to open stream: Permission denied in /var/www/html/vh09/story_submit.php on line 68, referer: http://www.yourline-online.com/story.php
    [client 69.17.65.22] PHP Warning: move_uploaded_file(): Unable to move '/tmp/phpbk3oiE' to 'pictures/13.jpg' in /var/www/html/vh09/story_submit.php on line 68, referer: http://www.yourline-online.com/story.php
    [client 69.17.65.22] PHP Notice: A session had already been started - ignoring session_start() in /var/www/html/vh09/stories.php on line 6, referer: http://www.yourline-online.com/story.php
    [client 69.17.65.22] PHP Notice: Use of undefined constant picture - assumed 'picture' in /var/www/html/vh09/story.php on line 60, referer: http://www.yourline-online.com/stories.php
    [client 69.17.65.22] PHP Warning: getimagesize(pictures/13.jpg): failed to open stream: No such file or directory in /var/www/html/vh09/story.php on line 61, referer: http://www.yourline-online.com/stories.php
    [Sun Dec 19 20:47:54 2004] [error] [client 69.17.65.22] File does not exist: /var/www/html/vh09/pictures/13.jpg, referer: http://www.yourline-online.com/story.php?story=13
    In case its relevant, I have placed the resize/upload script here:
    PHP Code:
    <?php
    $max_height 
    "60"
    $max_width "80"
                                                                                                                                 
    $image $HTTP_GET_VARS['image'];
                                                                                                                                 
    if (!
    $max_width)
      
    $max_width 80;
    if (!
    $max_height)
      
    $max_height 60;
                                                                                                                                 
    $size GetImageSize($image);
    $width $size[0];
    $height $size[1];
                                                                                                                                 
    $x_ratio $max_width $width;
    $y_ratio $max_height $height;
                                                                                                                                 
    if ( (
    $width <= $max_width) && ($height <= $max_height) ) {
      
    $tn_width $width;
      
    $tn_height $height;
    }
    else if ((
    $x_ratio $height) < $max_height) {
      
    $tn_height ceil($x_ratio $height);
      
    $tn_width $max_width;
    }
    else {
      
    $tn_width ceil($y_ratio $width);
      
    $tn_height $max_height;
    }
                                                                                                                                 
    $src ImageCreateFromJpeg($image);
    $dst ImageCreate($tn_width,$tn_height);
    ImageCopyResized($dst$src0000,
        
    $tn_width,$tn_height,$width,$height);
    header('Content-type: image/jpeg');
    ImageJpeg($dstnull, -1);
    ImageDestroy($src);
                                                                                                                                 
    ImageDestroy($dst);
                                                                                                                                 
    ?>
  2. #2
  3. No Profile Picture
    $post_count++;
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2001
    Location
    Southern MN, USA
    Posts
    1,143
    Rep Power
    21
    Well, your form method is post, so you would want to use $_POST not $HTTP_GET_VARS, and the image is in $_FILES, not $_POST (at least, i don't think it's in $_POST... I know it's in $_FILES.

    That could be your problem.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    37
    Rep Power
    10

    Newbie needs a little more help


    Thanks for your help. Is there a solution that would just fix this problem and let me come back to the notices when I am more exprienced?

    I am a newbie and I'm a little reluctant to rewrite this app on my first try at programming. You may be right about getting the notices to go away. This app comes from PHP and MySQL Web Development by Welling and Thomson so I am surprised that they got that wrong. This program works in connection with another program called stories and that may explain the ir use. Since you can only get to story.php through stories.php I probably should have posted that code, too. Here is the code for stories.php

    PHP Code:
    <?php
    // Listing 26.5
    // stories.php Is the Interface for Writers to Manage Their Stories
                                                                                    
    include('include_fns.php');
    session_start();
                                                                                    
    if (!
    check_auth_user()) {
    ?>
    <form action="login.php" method="post">
    <table border="0">
    <tr>
      <td>Username</td>
      <td><input size="16" name="username"></td>
    </tr>
    <tr>
      <td>Password</td>
      <td><input size="16" type="password" name="password"></td>
    </tr>
    </table>
    <input type="submit" value="Log in">
    </form>
    <?php
    }
    else {
      
    $conn db_connect();
                                                                                    
      
    $w get_writer_record($HTTP_SESSION_VARS['auth_user']);
                                                                                    
      print 
    'Welcome, '.$w['full_name'];
      print 
    ' (<a href="logout.php">Logout</a>)';
      print 
    '<p>';
                                                                                    
      
    $sql 'select * from stories where writer = \''.
             
    $HTTP_SESSION_VARS['auth_user'].'\' order by created desc';
      
    $result mysql_query($sql$conn);
                                                                                    
      print 
    'Your stories: ';
      print 
    mysql_num_rows($result);
      print 
    ' (<a href="story.php">Add new</a>)';
      print 
    '</p><br /><br />';
                                                                                    
      if (
    mysql_num_rows($result)) {
        print 
    '<table>';
        print 
    '<tr><th>Headline</th><th>Page</th>';
        print 
    '<th>Created</th><th>Last modified</th></tr>';
     while (
    $qry mysql_fetch_array($result)) {
          print 
    '<tr>';
          print 
    '<td>';
          print 
    $qry['headline'];
          print 
    '</td>';
          print 
    '<td>';
          print 
    $qry['page'];
          print 
    '</td>';
          print 
    '<td>';
          print 
    date('M d, H:i'$qry['created']);
          print 
    '</td>';
          print 
    '<td>';
          print 
    date('M d, H:i'$qry['modified']);
          print 
    '</td>';
          print 
    '<td>';
          if (
    $qry['published'])
            print 
    '[Published '.date('M d, H:i'$qry['published']).']';
          else {
            print 
    '[<a href="story.php?story='.$qry['id'].'">edit</a>] ';
            print 
    '[<a href="delete_story.php?story='.$qry['id'].'">delete</a>] ';
            print 
    '[<a href="keywords.php?story='.$qry['id'].'">keywords</a>]';
          }
         print 
    '</td>';
          print 
    '</tr>';
        }
        print 
    '</table>';
      }
                                                                                    
    }
    ?>
    The thing seems to work except for the picture upload. Those Warnings talk about the where the application fails (Or are these just misleading warnings?)
    [client 69.17.65.22] PHP Warning: move_uploaded_file(pictures/17.jpg): failed to open stream: Permission denied in /var/www/html/vh09/story_submit.php on line 68, referer: http://www.yourline-online.com/story.php
    [client 69.17.65.22] PHP Warning: move_uploaded_file(): Unable to move '/tmp/phpWyF9Fy' to 'pictures/17.jpg' in /var/www/html/vh09/story_submit.php on line 68, referer: http://www.yourline-online.com/story.php
    Could those problems sound like either a permission issue? It looks like it is creating an actual temporary image file in /tmp but it can't access it either because of permissions or because the resize failed. Is there a solution that would just fix this problem and let me come back to the notices when I am more exprienced?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2004
    Posts
    167
    Rep Power
    10
    you don't have the right folder permissions set to upload your image. chmod the folder and give it the correct permissions

    the rest of the notices could be turned off by working with php's error reporting settings: http://us2.php.net/error_reporting
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    37
    Rep Power
    10

    How do I know the folder's location


    I have seen lots of comments in the manual that there are problems with getImageSize (used by the page.php script) and imagecreatefromjpeg (used by the upload script). Where does the function get the instruction on where to place the /tmp file? Is it part of the function and can i change it? I would just put a tmp file in the path (/var/www/html/vhost/tmppic) and set the permissions there if I could.

    Second. I don't see where either the story.php or stories.php scripts calls the upload/resize script at all. Is it possible that my problem is that I just haven't set the picture to the right size?
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    37
    Rep Power
    10

    Permissions fixed it / unfortunately bad color with ImageCreateFromJpeg();


    Thanks for your kind help.

    The resize program get's called by a different program called page.php The script runds now after fixing the permissions (the permissions in the directory where the images were being transferrred to that caused the problem). Unfortunately, the images made from jpegs have really bad color quality. I'm off to look for fixes for scripts that use
    ImageCreateFromJpeg();
    ImageCreate();
    Last edited by rioguia; December 24th, 2004 at 06:26 AM. Reason: Forgot to say thank you
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    37
    Rep Power
    10

    Image Quality Fixed


    There are two problems above.

    1. The old gd function (LESS THAN VERSION 2?) in the above script was only 256 colors so truel color pictures look really bad. Fortunately you can just replace
    PHP Code:
    $dst ImageCreate($tn_width,$tn_height); 
    with
    PHP Code:
    $dst ImageCreateTrueColor($tn_width,$tn_height); 
    2. The other problem is an image quality setting issue. The original script called for making tiny thumbs so the quality was set to the lowest. If you make a thumb greater than 100 px then the setting has to be increased.
    Change
    PHP Code:
    ImageJpeg($dstnull, -1); 
    to
    PHP Code:
    ImageJpeg($dstnullANY REAL NUMBER >0 BUT <100); 

IMN logo majestic logo threadwatch logo seochat tools logo