/    Sign up×
Community /Pin to ProfileBookmark

Firefox & IE problem

hello guys

i have this serious problem

I have another form to upload an image in a folder on my server and the image location goes to a mysql database. then i retrieve the location and display the image

following code works in IE but not in FF

[CODE]

<?php

// connect to db
include ‘config.php’;
include ‘opendb.php’;

//Retrieves data from MySQL
$data = mysql_query(” SELECT ImgLoc FROM upload where id=’2′ “) or die(mysql_error());

//Puts it into an array
while($info = mysql_fetch_array( $data ))

$img = $info[‘ImgLoc’];

{
//Outputs the image and other data

echo “<img src=’$img’>”;

}

?>
[/CODE]

FF doesnt show any image but i can see image in IE

plz reply

thnx in advance
Jack

to post a comment
PHP

15 Comments(s)

Copy linkTweet thisAlerts:
@MrCoderDec 04.2007 — Where is your <HTML> and <BODY> tags?
Copy linkTweet thisAlerts:
@jack001authorDec 04.2007 — Where is your <HTML> and <BODY> tags?[/QUOTE]


this is in the value of $img = "C:/wamp/www/uploader/uploaded_files/1196768837-new.jpg"
Copy linkTweet thisAlerts:
@TheRaveDec 04.2007 — Is the generated html source the same in both browsers. If so your problem is html not php.
Copy linkTweet thisAlerts:
@harumphDec 04.2007 — You must use relative paths for images/files for Firefox.

i.e. - ../uploader/uploaded_files/1196768837-new.jpg

It looks at it as a security risk. It's that whole paranoia thing.
Copy linkTweet thisAlerts:
@jack001authorDec 05.2007 — You must use relative paths for images/files for Firefox.

i.e. - ../uploader/uploaded_files/1196768837-new.jpg

It looks at it as a security risk. It's that whole paranoia thing.[/QUOTE]


can u plz explain a bit, i am not understaning this...

after I upload a file a link of uploaded file location goes to mysql db plz see below code...

the link is like this "C:/wamp/www/uploader/uploaded_files/1196768837-new.jpg"

[CODE]
// connect to db
include 'config.php';
include 'opendb.php';

$name = $uploadFilename;
$desc = 'Uploaded';

$query = "INSERT INTO upload (name, desc) VALUES ('$name', '$desc')";

mysql_query($query) or die('Error, query failed');
[/CODE]
Copy linkTweet thisAlerts:
@TheRaveDec 05.2007 — As I said the problem is not a php problem. It is a html problem. Can you please post the generated html source code, then we can see exactly where the problem is.

  • - In IE or FF.

  • - Right click on the page

  • - Click View Source

  • - Copy the source

  • - Paste the source into a new post
  • Copy linkTweet thisAlerts:
    @jack001authorDec 05.2007 — this is form for uploading image

    [CODE]<?php

    // filename: upload.form.php

    // first let's set some variables

    // make a note of the current working directory relative to root.
    $directory_self = str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']);

    // make a note of the location of the upload handler
    $uploadHandler = 'http://' . $_SERVER['HTTP_HOST'] . $directory_self . 'upload.processor.php';

    // set a max file size for the html upload form
    $max_file_size = 30000; // size in bytes

    // now echo the html page
    ?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">

    <html lang="en">
    <head>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">

    <link rel="stylesheet" type="text/css" href="stylesheet.css">

    <title>Upload form</title>

    </head>

    <body>

    <form id="Upload" action="<?php echo $uploadHandler ?>" enctype="multipart/form-data" method="post">

    <h1>
    Upload form
    </h1>

    <p>
    <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_file_size ?>">
    </p>

    <p>
    <label for="file">File to upload:</label>
    <input id="file" type="file" name="file">
    </p>

    <p>
    <label for="submit">Press to...</label>
    <input id="submit" type="submit" name="submit" value="Upload me!">
    </p>

    </form>


    </body>

    </html>[/CODE]




    this is php code

    [CODE]<?php


    // first let's set some variables

    // make a note of the current working directory, relative to root.
    $directory_self = str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']);

    // make a note of the directory that will recieve the uploaded files
    $uploadsDirectory = $_SERVER['DOCUMENT_ROOT'] . $directory_self . 'uploaded_files/';

    // make a note of the location of the upload form in case we need it
    $uploadForm = 'http://' . $_SERVER['HTTP_HOST'] . $directory_self . 'upload.form.php';

    // make a note of the location of the success page
    $uploadSuccess = 'http://' . $_SERVER['HTTP_HOST'] . $directory_self . 'upload.success.php';

    // name of the fieldname used for the file in the HTML form
    $fieldname = 'file';



    // Now let's deal with the upload

    // possible PHP upload errors
    $errors = array(1 => 'php.ini max file size exceeded',
    2 => 'html form max file size exceeded',
    3 => 'file upload was only partial',
    4 => 'no file was attached');

    // check the upload form was actually submitted else print form
    isset($_POST['submit'])
    or error('the upload form is neaded', $uploadForm);

    // check for standard uploading errors
    ($_FILES[$fieldname]['error'] == 0)
    or error($errors[$_FILES[$fieldname]['error']], $uploadForm);

    // check that the file we are working on really was an HTTP upload
    @is_uploaded_file($_FILES[$fieldname]['tmp_name'])
    or error('not an HTTP upload', $uploadForm);

    // validation... since this is an image upload script we
    // should run a check to make sure the upload is an image
    @getimagesize($_FILES[$fieldname]['tmp_name'])
    or error('only image uploads are allowed', $uploadForm);

    // make a unique filename for the uploaded file and check it is
    // not taken... if it is keep trying until we find a vacant one
    $now = time();
    while(file_exists($uploadFilename = $uploadsDirectory.$now.'-'.$_FILES[$fieldname]['name']))
    {
    $now++;
    }

    // now let's move the file to its final and allocate it with the new filename
    @move_uploaded_file($_FILES[$fieldname]['tmp_name'], $uploadFilename)
    or error('receiving directory insuffiecient permission', $uploadForm);

    // If you got this far, everything has worked and the file has been successfully saved.
    // We are now going to redirect the client to the success page.


    // connect to db
    include 'config.php';
    include 'opendb.php';

    $name = $uploadFilename;
    $desc = 'This is description';

    $query = "INSERT INTO upload (name, desc) VALUES ('$name', '$desc')";

    mysql_query($query) or die('Error, query failed');


    header('Location: ' . $uploadSuccess);

    // make an error handler which will be used if the upload fails
    function error($error, $location, $seconds = 5)
    {
    header("Refresh: $seconds; URL="$location"");
    echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"'."n".
    '"http://www.w3.org/TR/html4/strict.dtd">'."nn".
    '<html lang="en">'."n".
    ' <head>'."n".
    ' <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">'."nn".
    ' <title>Upload error</title>'."nn".
    ' </head>'."nn".
    ' <body>'."nn".
    ' <div id="Upload">'."nn".
    ' <h1>Upload failure</h1>'."nn".
    ' <p>An error has occured: '."nn".
    ' <span class="red">' . $error . '...</span>'."nn".
    ' The upload form is reloading</p>'."nn".
    ' </div>'."nn".
    '</html>';
    exit;
    } // end error handler

    ?>[/CODE]
    Copy linkTweet thisAlerts:
    @TheRaveDec 05.2007 — As I said this is a [b]HTML[/b] problem.

    The source code you posted works. You said it works in Internet Explorer. So all the php and the code you posted works fine.

    Its is the [b]HTML[/b] that is the problem.

    Please can you post the [b]generated HTML[/b] so we can find the problem.

    If you don't know how to do this please follow the steps I posted:

  • - In IE or FF

  • - Right click on the page

  • - Click View Source

  • - Copy the source

  • - Paste the source into a new post


  • If you have any problems with these steps please ask.


    -----

    Please stop posting the php as we know it works.

    You [b]HAVE[/b] to post the [b]generated [i]HTML[/i][/b] otherwise we cannot find your problem.

    We cannot help you unless you give us the information we ask for.
    Copy linkTweet thisAlerts:
    @jack001authorDec 05.2007 — this is generated html after i upload the image

    [CODE]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">

    <html lang="en">
    <head>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">

    <link rel="stylesheet" type="text/css" href="stylesheet.css">

    <title>Successful upload</title>

    </head>

    <body>

    <div id="Upload">

    <h1>File upload</h1>
    <p>Congratulations! Your file upload was successful</p>
    </div>

    </body>

    </html>[/CODE]




    this is generated html of teh displayimage.php

    [CODE]<img src='C:/wamp/www/uploader/uploaded_files/1196768837-new.jpg'>[/CODE]

    same in IE and FF
    Copy linkTweet thisAlerts:
    @TheRaveDec 05.2007 — Ahh ok. Thank you. Now we can see the problem.

    The src attribute of the image tag should not link to a local file.

    The part in bold is incorrect:
    &lt;img src='[b]C:/wamp/www/uploader/uploaded_files/1196768837-new.jpg[/b]'&gt;
    Internet explorer displays this because it allows browsing of local directories. Firefox does not allow browsing of local directories unless the page is local (which technically it isn't since its being served by WAMP).

    This is the html problem. The html problem is caused because you are putting the wrong value into the src attribute.

    Since the src attribute is being grabbed from the database your problem is what is stored in the database.

    The value stored in the database should not be a local path (e.g. "C:exmaplefolderexampleimage.jpg") but a URL path whether absolute (e.g. "localhost/uploader/uploaded_files/1196768837-new.jpg" or "www.example.com/uploader/uploaded_files/1196768837-new.jpg'") or relative (e.g. "uploaded_files/1196768837-new.jpg'").

    You are using the same path for the destination of the copy (which should be local) and the output path (which should be URL). This is incorrect.

    The destination of the copy should be:

    "C:/wamp/www/uploader/uploaded_files/1196768837-new.jpg"

    So that is correct.

    The destination of the URL path should be:

    "uploaded_files/1196768837-new.jpg"

    Obviously depending on the location of your files.

    Add a new variable to store the URL path and to put it in the database.

    Local paths:

    - For dealing with local files (such as when copying, manipulating, etc)

    URL paths:

    - For serving files (such as images, styles, etc)

    It helps if you look into learning the difference between:

    "C:/wamp/www/uploader/uploaded_files/1196768837-new.jpg"

    and

    "localhost/uploader/uploaded_files/1196768837-new.jpg"

    If you need anymore information on Local and URL paths give me a shout.
    Copy linkTweet thisAlerts:
    @jack001authorDec 05.2007 — Thanx Rave

    Your solved my problem

    now I can start my project


    God Bless U
    Copy linkTweet thisAlerts:
    @harumphDec 05.2007 — Didn't I say that?
    Copy linkTweet thisAlerts:
    @MrCoderDec 05.2007 — Didn't I say that?[/QUOTE]

    Yep, but you forget that people only read something if it is over 2 pages long ?
    Copy linkTweet thisAlerts:
    @harumphDec 05.2007 — hehe.
    Copy linkTweet thisAlerts:
    @TheRaveDec 05.2007 — Yep, but you forget that people only read something if it is over 2 pages long ?[/QUOTE]
    My thoughts exactly.
    ×

    Success!

    Help @jack001 spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 6.16,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @nearjob,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,
    )...