Seeing an web page instead of seeing an image file

The Upload Form code (below) that moves files from Temp folder to /Upload folder.
It also copies NoInfoAvailable.png if a file is not uploaded, so that when a link is selected it will show a message “no info available”. Is it possible to show a NoInfoAvailble page instead of a NoInfoAvailable image? so that users can select a “back to previous page” button, on that page, for their convenience? if so, how can i change this code to accomplish that?

    if (isset($_POST['form_submitted'])):

    // $randomString needed regardless of passing tests so put outside error condition
    $randomString = time();

    if((isset($_FILES) && $_FILES['file']['error'] != 0) || !isset($_FILES)){

        //Unable to upload file to temp
        //Set variable for final move/copy condtion with no message
        $error = '';

       }else{

        $allowedExts = array("doc", "docx", "gif", "jpeg", "jpg", "txt", "rtf", "pdf", "png",  "txt");
        $temp = explode(".", $_FILES['file']['name']);
        $extension = strtolower( end($temp) );

        if(!in_array($extension,$allowedExts)){

            $error = '<div id="errorMessage">Error: Invalid File Name </div>';

        }elseif($_FILES['file']['size'] >= 100000){

            $error = '<div class="errorMessage1">Error: Image File Size Exceeds 100  KB Limit </div>';

        }         
    }

        if(!isset($error)){
            $uploadedFile = $_FILES['file']['tmp_name'];
            $thumbnail = $_SESSION['user_id'] . '-' . $randomString . "." . $extension;
            move_uploaded_file($uploadedFile, "upload/" . $thumbnail);
        }else{
            //Make sure NoInfo image has png extension
            $thumbnail = $_SESSION['user_id'] . '-' . $randomString . ".png";
            copy("upload/NoInfoAvailable.png", "upload/" . $thumbnail);
        }
            $_SESSION['thumbnail'] = $thumbnail;
            $file_location = '<a href="http://www....com/upload/' . $thumbnail . '">' .  $thumbnail . '</a>';

endif; 
if(isset($error)){echo $error;}

Any assistance will be appreciated.

I would think you could just replace that copy code with a header. Notice I also moved the session thumbnail and file location lines up as they would no be SET.

<?php
if (isset($_POST['form_submitted'])):

// $randomString needed regardless of passing tests so put outside error condition
$randomString = time();

if((isset($_FILES) && $_FILES['file']['error'] != 0) || !isset($_FILES)){

    //Unable to upload file to temp
    //Set variable for final move/copy condtion with no message
    $error = '';

   }else{

    $allowedExts = array("doc", "docx", "gif", "jpeg", "jpg", "txt", "rtf", "pdf", "png",  "txt");
    $temp = explode(".", $_FILES['file']['name']);
    $extension = strtolower( end($temp) );

    if(!in_array($extension,$allowedExts)){

        $error = '<div id="errorMessage">Error: Invalid File Name </div>';

    }elseif($_FILES['file']['size'] >= 100000){

        $error = '<div class="errorMessage1">Error: Image File Size Exceeds 100  KB Limit </div>';

    }         
}

    if(!isset($error)){
        $uploadedFile = $_FILES['file']['tmp_name'];
        $thumbnail = $_SESSION['user_id'] . '-' . $randomString . "." . $extension;
        move_uploaded_file($uploadedFile, "upload/" . $thumbnail);
        $_SESSION['thumbnail'] = $thumbnail;
        $file_location = '<a href="http://www....com/upload/' . $thumbnail . '">' .  $thumbnail . '</a>';
    }else{
        //Make sure NoInfo image has png extension
       // $thumbnail = $_SESSION['user_id'] . '-' . $randomString . ".png";
       // copy("upload/NoInfoAvailable.png", "upload/" . $thumbnail); 
       header{"location: NoInfoAvailble.php");
       exit;
    }
       

endif;
if(isset($error)){echo $error;}
?>

Thanks again for replying.
However, with that modification, when a file isn’t uploaded, upon Submit, the NoInfoAvailable.php page appears. I probably wasn’t clear in my initial posting.

The PHP script’s Upload Form that I’m using ultimately uploads a video. It has been modified so that the user, after filling in the Form, can optional add an image file to his Form info, then the Submit button uploads the Form info and (optional) image.

After Submit the next page is where the user selects a video file to upload. When the video is searched a link appears next to the video thumbnail image. The link is for viewing the (optional) image file. When a file has not been uploaded via the Form, the link shows the NoInfoAvailable.png successfully. I’m now looking for a modification that when a file has not been uploaded via the Form, the link shows the NoInfoAvailable.php, instead of NoInfoAvailable.png.

Would this do it??? Modify path as needed.

if(!isset($error)){
        $uploadedFile = $_FILES['file']['tmp_name'];
        $thumbnail = $_SESSION['user_id'] . '-' . $randomString . "." . $extension;
        move_uploaded_file($uploadedFile, "upload/" . $thumbnail);
        $_SESSION['thumbnail'] = $thumbnail;
        $file_location = '<a href="http://www....com/upload/' . $thumbnail . '">' .  $thumbnail . '</a>';
    }else{
        //Make sure NoInfo image has png extension
       // $thumbnail = $_SESSION['user_id'] . '-' . $randomString . ".png";
       // copy("upload/NoInfoAvailable.png", "upload/" . $thumbnail);
       $_SESSION['thumbnail'] = "NoInfoAvailble.php";
       $file_location = '<a href="http://www....com/' . $thumbnail . '">' .  $thumbnail . '</a>';
    }

Much thanks again for your reply.
When I run the Form and then select the link, after not uploading an image,
I see www…com/upload/NoInfoAvailable.php.
How can it just be: www…com/NoInfoAvailable.php ?

I look forward to any additional assistance.

OK, so I’m a bit confused.
Do you want the image copied? Yes I assume.
But you wish the LINK associated with this image to go to NoInfoAvailable.php.
Does that sound right?
If this is the case, do we really need to copy the image? Just use the default image for the link icon.
Yes, no… Please explain.

I believe this is what you want.

    if(!isset($error)){
        $uploadedFile = $_FILES['file']['tmp_name'];
        $thumbnail = $_SESSION['user_id'] . '-' . $randomString . "." . $extension;
        move_uploaded_file($uploadedFile, "upload/" . $thumbnail);
        $_SESSION['thumbnail'] = $thumbnail;
        $file_location = '<a href="http://www....com/upload/' . $thumbnail . '">' .  $thumbnail . '</a>';
    }else{    
        $file_location = '<a href="http://www....com/NoInfoAvailble.php"><img src="upload/NoInfoAvailable.png" alt="No Image"></a>';
    }

Thanks again for your reply and assistance. Greatly appreciated.
Sorry for any confusion. Yes, I’d like to instead of copy the NoInfoAvailanle.png,
I’d like the user to see a NoInfoAvailable page.
Sorry to report that after trying your latest code, I still see
I see www…com/upload/NoInfoAvailable.php.
Any help with just seeing: www…com/NoInfoAvailable.php
will be appreciated.

That’s odd. I posted an image tag inside the <a> tags. How is $file_location rendered on the next page?

Does what I’m using look correct?
if (isset($_POST[‘form_submitted’])):

 // $randomString needed regardless of passing tests so put outside error condition
 $randomString = time();

if((isset($_FILES) && $_FILES['file']['error'] != 0) || !isset($_FILES)){

    //Unable to upload file to temp
  //Set variable for final move/copy condtion with no message
  $error = '';

  }else{

 $allowedExts = array("doc", "docx", "gif", "jpeg", "jpg", "txt", "rtf", "pdf", "png",     "txt");
 $temp = explode(".", $_FILES['file']['name']);
 $extension = strtolower( end($temp) );

 if(!in_array($extension,$allowedExts)){

    $error = '<div id="errorMessage">Error: Invalid File Name </div>';

}elseif($_FILES['file']['size'] >= 100000){

      $error = '<div class="errorMessage1">Error: Image File Size Exceeds 100  KB Limit </div>';  }
 }
 if(!isset($error)){
    $uploadedFile = $_FILES['file']['tmp_name'];
    $thumbnail = $_SESSION['user_id'] . '-' . $randomString . "." . $extension;
    move_uploaded_file($uploadedFile, "upload/" . $thumbnail);
    $_SESSION['thumbnail'] = $thumbnail;
    $file_location = '<a href="http://www....com/upload/' . $thumbnail . '">' .  $thumbnail . '</a>';
}else{
    $file_location = '<a href="http://www....com/NoInfoAvailable.php"><img src="upload/NoInfoAvailable.png" alt="No Image"></a>';
}
endif;
 if(isset($error)){echo $error;
 }

Yes and on my test, if no file is selected the variable $file_location is set to an image/link. When echoed, it shows the image like this (on my copy) which links to www…com/upload/NoInfoAvailable.php.

Thanks again for your reply.
I only see this in the browser:
http://www.thedomainname.com/upload/
after I don’t choose a file to upload and then Submit the Form, and then select the page link. It’s the same outcome as when I select the wrong file format to upload (and proceed). Both outcomes show http://www.thedomainname.com/upload/ and “Access Forbbiden” on the page that appears.
Any additional help will be welcomed.

When you view html source code do you see <img src="upload/NoInfoAvailable.png" alt="No Image"> You should be seeing the image tag. Maybe the path to the file is not correct.

The reason I was asking about how you render the variable on the next page is because I wasn’t sure if you were just echoing the variable(s) or building a link with parts. Can you post or explain what you are doing code wise with $file_location?

Thanks again for your reply.
I looked in the html source code from the Upload Form page, the html source code from the Access Forbidden page and the html source code from the (search) Results page and I didn’t see anything with NoInfoAvailable.

Regarding “code wise with $file location”, other than what is posted in #10, I’m not clear on what you’re asking for.

Thanks again for your replies.
Any additional help will be appreciated.

But that doesn’t answer where you are echoing $file location.

Thanks for your reply.
Whe I try to view page source where the Error messages appear, when I right-click View Source I see this: see attached image

NO not the error page… I assume it would be when viewing inner_upload_video.htm but then again how are you echoing $file location if it’s a htm page. This is what I am not following with your template system.
Again how are you echoing $file_location and what does it show when you view the source.

So what is causing this error to show? We are currently not setting $_SESSION['thumbnail']. Is this required?

So the coding where these two values has never been provided. Is the $file_location used for the “link” and $_SESSION[‘thumbnail’] used for “what is put between <a> tags”? IF THAT’S the case, Then my single line, e.g.

<a href="http://www....com/NoInfoAvailble.php"><img src="upload/NoInfoAvailable.png" alt="No Image"></a>

would need to be broken into two parts Or just have the thumbnail part added.

 $_SESSION['thumbnail'] = 'NoInfoAvailable.png';
 $file_location = '<a href="http://www....com/NoInfoAvailble.php"><img src="upload/NoInfoAvailable.png" alt="No Image"></a>';

I’m guessing at this point as I don’t know where or how these two values are using.

Thanks again for your reply.
I’m sorry I’m not a coder, and therefore don’t know how to answer your questions about $file_locations, or how exactly the templated script works, as I’m not the author. I can tell you that I tried your suggestion of “two parts” without success. I can tell you that the “thumbnail” refers to the column name in the db that stores the uploaded files.
I’m not sure if this will shed some light, but when when I received past help with this Form, regarding $Session, I was told: “You should try moving the $_FILES calls to the uploader_finished.php file. Right now you’re INSERTING to the database before the file information has been INSERTED.
I think the best way to do this would be to add a session variable in the uploader.php and then use that session variable in the uploader_finished.php”. And it worked successfully.

I look forward to any additional assistance.

This might be a silly question but have you made a NoInfoAvailble.php page?

I still think it might be an image path issue. If you add full url does that help regarding error?


        $_SESSION['thumbnail'] = 'NoInfoAvailable.png';
        $file_location = '<a href="http://www....com/NoInfoAvailble.php"><img src="http://www....com/upload/NoInfoAvailable.png" alt="No Image"></a>';

Thanks for your message.
Yes I have a NoInfoAvailable.php page.
And have added the full url’s without success (and corrected the spelling of “Available”).
Any other assistance will be welcomed.