Hola,

I have a form which is to format and upload pictures onto the server. The following code is what I have so far. I keep getting a parse error on line 49, but the script will echo the following:

File is not the right type of image.
File MIME type: image/jpeg is not a jpeg, gif, or png.

Obviously, image/jpeg IS a jpeg. I can't figure it out for the life of me. Please help!

Ras.

Code:

include ('includes.php');

$graphic = $HTTP_POST_FILES['graphic']['tmp_name'];
$graphic_name = $HTTP_POST_FILES['graphic']['name'];
$graphic_size = $HTTP_POST_FILES['graphic']['size'];
$graphic_type = $HTTP_POST_FILES['graphic']['type'];
extract($HTTP_POST_VARS);

/
error checking & formatting.
/

if ($graphic_type !="image/jpeg" || "image/gif" || "image/png")
{
	echo "File is not the right type of image.<br>";
	echo "File MIME type: $graphic_type is not a jpeg, gif, or png.";
	exit;
}
else
{
	$graphic_name = str_replace(' ', '_', $graphic_name);
}	
switch($image_type)  

// on the form as a radio button taken with extract() in script
{
case 'a' :
$directory = 'a';
$graphic_name = 's'.$graphic_name;
break;
case 'b' :
$directory = 'b';
$graphic_name = 'a
'.$graphic_name;
break;
case 'c' :
$directory = 'c';
$graphic_name = 'p_'.$graphic_name;
break;
}
$upload = '/directory/subdirectory/images/'.$directory.'/'.$graphic_name;

Code snippet from the form:

<tr>
<td valign="top" width="33%"><input type="radio" name="image_type" value="a">a</td>
<td valign="top" width="33%"><input type="radio" name="image_type" value="b">b</td>
<td valign="top" width="33%"><input type="radio" name="image_type" value="c">c</td></tr>
<tr><td><input type="file" name="graphic" size="32"></td></tr>
</tr>

    Instead of:

    if($graphic_type != "image/jpeg" || "image_gif" || "image_png") {
      // shtuff
    }
    

    maybe try something like:

    if($grpahic_type != "image/jpeg" && $grpahic_type != "image/png" && $graphic_type != "image/png") {
      // shtuff
    }
    

    Any better?

      if what he said doesn't work, maybe tell us what line 49 is for sure

        🙁

        code looks like this now. Incidentally, line 49 was the end of the switch statement.

        if(isset($graphic_type))
        { if($grpahic_type!="image/jpeg"&&$grpahic_type!="image/png"&&$graphic_type!="image/png")
        {
        echo "File is not the right type of image.<br>";
        echo "File MIME type: $graphic_type is not a jpeg, gif, or png.";
        exit;
        }
        else

        	{
        		$graphic_name = str_replace(' ', '_', $graphic_name);
        		echo $graphic_name;
        		exit;
        	}	
        	switch($image_type)
        	{
        		case 'a' :
        			$directory = 'a';
        			$graphic_name = 'a_'.$graphic_name;
        			break;
        		case 'b' :
        			$directory = 'b';
        			$graphic_name = 'b_'.$graphic_name;
        			break;
        		case 'c' :
        			$directory = 'c';
        			$graphic_name = 'c_'.$graphic_name;
        			break;
        	}
        }
        else
        {echo "poop on you.";exit;}

          the following gives me NO parse errors, you were missing brackets

          <?
          if(isset($graphic_type))
          {
          if($graphic_type != "image/jpeg" && $graphic_type != "image/png" && $graphic_type != "image/png")
          { 
          echo "File is not the right type of image.<br>"; 
          echo "File MIME type: $graphic_type is not a jpeg, gif, or png."; 
          exit; 
          } 
          else
          { 
          $graphic_name = str_replace(' ', '_', $graphic_name); 
          } 
          switch($image_type) 
          { 
          case 'a' : 
          $directory = 'a'; 
          $graphic_name = 'a_'.$graphic_name; 
          break; 
          case 'b' : 
          $directory = 'b'; 
          $graphic_name = 'b_'.$graphic_name; 
          break; 
          case 'c' : 
          $directory = 'c'; 
          $graphic_name = 'c_'.$graphic_name; 
          break;
          }
          }
          else
          {echo "poop on you. you don't know what the hell you're doing!";exit;}
          ?>

            I tried that script, but keep getting errors on the $graphic_type line.

            Code (verbatim):

            <?php

            include ('LNEONLINE.php');
            
            $graphic = $HTTP_POST_FILES['graphic']['tmp_name'];
            $graphic_name = $HTTP_POST_FILES['graphic']['name'];
            $graphic_size = $HTTP_POST_FILES['graphic']['size'];
            $graphic_type = $HTTP_POST_FILES['graphic']['type'];
            extract($HTTP_POST_VARS);

            if($graphic_type!="image/jpeg"&&$graphic_type!="image/png"&&$graphic_type!="image/png")
            {
            echo
            "File is not the right type of image.<br>";
            echo
            "File_MIME_type:$graphic_type_is_not_a_jpeg,gif,or_png.";
            exit;
            }

            else
            {
            $graphic_name
            =str_replace(' ','',$graphic_name);
            }

            switch($image_type)
            {

            case'speaker':
            $directory
            ='speakers';
            $graphic_name='s'.$graphic_name;
            break;
            case
            'article':
            $directory='articlepics';
            $graphic_name
            ='a'.$graphic_name;
            break;

            case'product':
            $directory
            ='products';
            $graphic_name='p'.$graphic_name;
            break;
            }

            ?>

            error:

            Parse error: parse error in /root/experiment/content_uploader.php on line 11

            I have no clue why.

              are there a bunch of underscores in the equality of the if, make them spaces

                Just saw that, but I didn't type it! The copy/paste onto the forum turned spaces into underscores...perhaps that's doing something to the script. I am retyping everything by hand again...hope that works! be back with results.

                  you may try using the php tag button when posting code, that will hopefully solve the problem and will make it easier for us to read the code

                  and yeah let us know what you come up with

                    Ok, back to square one. I retyped all the code, and I get an error on the infamous line 49.

                    Code (verbatim w/ line 49 comment added):

                    <?php
                    
                    include ('includes.php');
                    
                    $graphic = $HTTP_POST_FILES['graphic']['tmp_name'];
                    $graphic_name = $HTTP_POST_FILES['graphic']['name'];
                    $graphic_size = $HTTP_POST_FILES['graphic']['size'];
                    $graphic_type = $HTTP_POST_FILES['graphic']['type'];
                    
                    extract($HTTP_POST_VARS);
                    
                    /*****************************************************************************************************
                    	error checking & formatting.
                    *****************************************************************************************************/
                    
                    if(isset($graphic_type))
                    {
                    	echo $graphic_type;
                    	if($graphic_type != 'image/jpeg' && $graphic_type != 'image/gif' && $graphic_type != 'image/png')
                    	{
                    		echo "File is not the right type of image.<br>";
                    		echo "File MIME type: $graphic_type is not a jpeg, gif, or png.";
                    		exit;
                    	}
                    	else
                    	{
                    		$graphic_name = str_replace(' ', '_', $graphic_name);
                    	}
                    }
                    else
                    {
                    	echo "poop.";
                    	exit;
                    }
                    
                    switch($image_type)
                    {
                    	case 'speaker':
                    		$directory = 'speakers';
                    		$graphic_name = 's_'.$graphic_name;
                    		break;
                    	case 'article':
                    		$directory = 'articlepics';
                    		$graphic_name = 'a_'.$graphic_name;
                    		break;
                    	case 'product':
                    		$directory = 'products';
                    		$graphic_name = 'p_'.$graphic_name;
                    		break;  // I am line 49.
                    }
                    ?> 

                    Ras.

                      i'm not getting any errors, except i got one on your comment block, you need /, not / , notice space in second one, and

                      try commenting out your include.php, there may be an error in there, cuz there certainly isn't one in the code you posted

                        I commented out the include (as for troubleshooting, there was nothing in the include that was in the code) and it worked...now to find the error in the include! Learned a valuable lesson on this one...I'm leaving the thread open until the include stuff is sorted out, just in case.

                        You are my hero, stolzyboy!

                        Ras.

                          Ok, the include got fixed, now to upload the file to the server. is this the proper code for uploading the image?

                          	$upfile = '/root/mysite.com/public_html/images/'.$directory.'/'.$graphic_name;
                          
                          if (is_uploaded_file($graphic)) 
                          	{
                          		if (!move_uploaded_file($graphic, $upfile))
                          		{
                          			echo "Could not move file into destination directory.<br>";
                          			move_uploaded_file($graphic, $upfile);
                          			echo "Had to recycle. Moving on...<br>";
                          			break;
                          		}
                          	}
                          	else
                          	{
                          		echo 'Possible file upload attack. Filename: '.$graphic_name;
                          		exit;
                          	}
                          
                          echo "File uploaded successfully<br><br>";
                          exit;
                          

                          I'm getting a host of errors including "no such file or directory", but I suspect they are on my webserver's side (have to yell at him about that).

                            use this instead

                            $upfile = '/root/mysite.com/public_html/images/'.$directory.'/'.$_FILES['Picture']['name'];
                            move_uploaded_file($_FILES['graphic']['tmp_name'], $upfile);
                            

                              Seems like it should work. I keep getting these errors though. I'm sure it has nothing to do with the code, and more to do with webserver permissions, but since I don't handle (and have no experience in) that, I'm not sure what I can do to aid matters there. Any tips?

                              errors:
                              Warning: Unable to create '/root/mysite.com/public_html/images/speakers/s_picture.jpg': No such file or directory

                              Warning: Unable to move '/tmp/phpxTRys5' to '/root/mysite.com/public_html/images/speakers/s_picture.jpg'

                                you need to make sure that PHP has write permissions in the directory

                                  How would I go about doing that? They are hosted remotely for the time being, so anything having to do with the server needs to be emailed out to the hosting company. If it's something I can do here locally, then that's good.

                                  Ras.

                                    your host doesn't give you ftp access or telnet access, usually on *nix boxes, you can chmod files/directories thru ftp

                                      Write a Reply...