Jump to content

Working on Image Preview During Submission Process. All Working Well Exce...


Modernvox

Recommended Posts

  What's up brothers..

 

For the past week I have been Working on implementing an Image Preview During the Submission Process. All is Working Well up until lines 104-115.

 

Seems one or the other is allowed "That is, either the image will show alone, or text will show alone (If i attempt to display both at once only the text shows and the image shows as a 403 Forbidden access error.

 

In addition, I would also like to know if any of you have experience with image resizing as  I only want to display a set thumbnail size.

 

Here is the code in question. As always "your time is greatly appreciated".

 

 <?php


error_reporting(E_ALL);
ini_set("display_errors", 1);
if ($_POST['submit']){


if (!$_POST['location'] || !$_POST['actual_location'] || !$_POST['name'] || !$_POST['influences'] || !$_POST['exp'] || !$_POST['bio']) {
die('Missing required fields detected');
}

$location= $_POST['location'];
$actual_location= $_POST['actual_location'];
$name= $_POST['name'];
$influences= $_POST['influences'];
$exp= $_POST['exp'];
$bio= $_POST['bio'];


$errorlist= array();
$maxsize=28480;

if ($location== "") {
$errorlist[]= "ERROR: <font color= \"red\">You must choose a location</font>";
}

       if ($actual_location== "") {
           $errorlist[]= "ERROR: <font color= \"red\">You must enter your actual location for user search</font>";
           }

                if ($name== "" || strlen($name) >50) {
                    $errorlist[]= "ERROR: <font color= \"red\">Name must between 1-50 characters in                           length</font>";
                    }

                         if ($influences == "" || strlen($influences) >30) {
                            $errorlist[] = "ERROR:  <font color= \"red\">1-30 characters allowed for influences</font>";
                           }

                                    if ($exp== "" || strlen($exp) >100) {
                                        $errorlist[]= "ERROR: <font color=                                        \"red\">1-100 characters allowed                                             for experience</font>";
                                       }

                         if ($bio == "" || strlen($bio) >250) {
                             $errorlist[]= "ERROR: <font color= \"red\">1-                             250 characters allowed for bio"; 
                             echo" you currently have strlen($bio)</font>";
                            }

				if (sizeof($errorlist) > 0) {
	                echo "Please review and correct the following erro                        rs by clicking your browsers back button <br/>";
	              foreach ($errorlist as $e) {
		            echo "$e <br/>";
	                }exit();
	            } 

$maxsize=28480;
$photo= $_FILES['photo'];             
    if (!is_uploaded_file($_FILES['photo']['tmp_name'])) { 
                     $errorlist = "ERROR: <font color= \"red\">You must upload a file!</font>"; 
                    
                    } 

        if ($_FILES['photo']['type'] != "image/gif" AND 
            $_FILES['photo']['type'] != "image/pjpeg" AND 
            $_FILES['photo']['type'] !="image/jpeg") { 
            $errorlist = "ERROR: <font color= \"red\">You may only upload .gif or .jpeg files</font>"; 
         
            }

if ($_FILES['photo']['size']> $maxsize) {
$errorlist = "ERROR: <font color= \"red\">file must be less than $maxsize bytes.</font>"; 
unlink($_FILES['photo']['tmp_name']); 
}

else {
move_uploaded_file($_FILES['photo']['tmp_name'], "./uploads/".$_FILES['photo']['name']); [b]//line104[/b]
print "<img src=\"./uploads/{$_FILES['photo']['name']}"; 

echo "<b><font color= \"black\">Experience:</font></b>" . $exp. "</br>"; 
echo $influences . "<br/>";
echo $actual_location . "<br/><br/>";
echo $bio . "<br/>";   [b]//line110 [/b]
   }
} 

Link to comment
Share on other sites

On line 105 (print statement), you didn't close your img tag...

 

Thanks for pointing that out Andy, but it had no effect. If i comment out the 4 echo statements the image shows. It's either the text or image, never both.

 

Are you sure about that? This is what is in the script above

print "<img src=\"./uploads/{$_FILES['photo']['name']}"; 

 

Which will produce something like this

<img src="./uploads/filename.jpg

 

Since you don't close the src parameter (or the img tag), the browser gets confused. I'm guessing it works when you don't include the other echos because the browser is not seeing any other content after that so it "assumes" that is the end of the source and "fixes" the mistake. Change that line to this:

print "<img src=\"./uploads/{$_FILES['photo']['name']}\" />"; 

 

Are you using IE for testing? If so, try switching to FF. IE has a habit of trying to "correct" malformed HTML. So, if you have errors in the HTML code it may look fine in IE, but not in other browsers. Also, when you have these types of error, it helps to look at the actual HTML produced. Trying to spot HTML errors in PHP code can be difficult.

Link to comment
Share on other sites

On line 105 (print statement), you didn't close your img tag...

 

Thanks for pointing that out Andy, but it had no effect. If i comment out the 4 echo statements the image shows. It's either the text or image, never both.

 

Are you sure about that? This is what is in the script above

print "<img src=\"./uploads/{$_FILES['photo']['name']}"; 

 

Which will produce something like this

<img src="./uploads/filename.jpg

 

Since you don't close the src parameter (or the img tag), the browser gets confused. I'm guessing it works when you don't include the other echos because the browser is not seeing any other content after that so it "assumes" that is the end of the source and "fixes" the mistake. Change that line to this:

print "<img src=\"./uploads/{$_FILES['photo']['name']}\" />"; 

 

Are you using IE for testing? If so, try switching to FF. IE has a habit of trying to "correct" malformed HTML. So, if you have errors in the HTML code it may look fine in IE, but not in other browsers. Also, when you have these types of error, it helps to look at the actual HTML produced. Trying to spot HTML errors in PHP code can be difficult.

 

Ahhhh..You the man. Not only did I leave out the ending slash />  I also left out the double quotes \"

Thanks a bunch....Do you recommend any tutorials on how to resize these images to a thumbnail?

 

Thanks again

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.