Jump to content

Display uploaded images


andy_b_1502

Recommended Posts

Hi everyone!!  :D

 

I have looked into how the upload script works and this is what i have:

 

<?php
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 20000))
   {
   if ($_FILES["file"]["error"] > 0)
     {
     echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
     }
   else
     {
     echo "Upload: " . $_FILES["file"]["name"] . "<br />";
     echo "Type: " . $_FILES["file"]["type"] . "<br />";
     echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
     echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

    if (file_exists("upload/" . $_FILES["file"]["name"]))
       {
       echo $_FILES["file"]["name"] . " already exists. ";
       }
     else
       {
       move_uploaded_file($_FILES["file"]["tmp_name"],
       "upload/" . $_FILES["file"]["name"]);
       echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
       }
     }
   }
else
   {
   echo "Invalid file";
   }
?> 

 

Which is un-tested at the moment, but let's just say for talking sake it worked 100% what elements of this script would i be looking at to display the files uploaded on to another page, in my case my homepage?

 

ive found as to yet, that the uploads have to be stored on a file somewhere on my server, which i've set up. But i thought it would be just as easy to have a field in my table named upload and display it within the table next to the other results? instead i just get whatever the file name is named.jpg.

 

Any help in looking towards the answer? many thanks in advance guys!

 

 

Link to comment
Share on other sites

Not quite sure what you are getting at, but you would need this:

 

<?php 
$file_path = "upload/" . $_FILES["file"]["name"];
?>

 

If you have a table of uploads or whatever you want to call it, be sure to have a field for this path.  For example, having image_path as a column in your table.  Then, you would have to save $file_path into that field.  When displaying this same image, all you would need is something like this:  assuming you already worked your mysql etc...

 

<?php

echo '<img src="'.$row['image_path'].'" />';

?>

Link to comment
Share on other sites

Also worth familiarising yourself with this mate - http://uk3.php.net/manual/en/features.file-upload.php . Get to know the $_files array - it'll help you a lot cos i know i found it all a bit confusing at first.

 

 

 

Hi everyone!!  :D

 

I have looked into how the upload script works and this is what i have:

 

<?php
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 20000))
   {
   if ($_FILES["file"]["error"] > 0)
     {
     echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
     }
   else
     {
     echo "Upload: " . $_FILES["file"]["name"] . "<br />";
     echo "Type: " . $_FILES["file"]["type"] . "<br />";
     echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
     echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

    if (file_exists("upload/" . $_FILES["file"]["name"]))
       {
       echo $_FILES["file"]["name"] . " already exists. ";
       }
     else
       {
       move_uploaded_file($_FILES["file"]["tmp_name"],
       "upload/" . $_FILES["file"]["name"]);
       echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
       }
     }
   }
else
   {
   echo "Invalid file";
   }
?> 

 

Which is un-tested at the moment, but let's just say for talking sake it worked 100% what elements of this script would i be looking at to display the files uploaded on to another page, in my case my homepage?

 

ive found as to yet, that the uploads have to be stored on a file somewhere on my server, which i've set up. But i thought it would be just as easy to have a field in my table named upload and display it within the table next to the other results? instead i just get whatever the file name is named.jpg.

 

Any help in looking towards the answer? many thanks in advance guys!

Link to comment
Share on other sites

Okay, getting in a bit of a mess here trying different things out.

 

<form method="post" action="basicpackage-send.php">
Compnay Name:<br /><br />
<input type="text" name="company_name" id="compnay_name" size="30" /><br /><br />
Six Bullet Point Description:<br /><br />
<textarea name="basicpackage_description" id="basicpackage_description" rows="7" cols="21">.
.
.
.
.
.
</textarea><br /><br />
Location:<br /><br />
<input type="text" name="location" id="location" size="50" /><br /><br />
Postcode:<br /><br />
<input type="text" name="postcode" id="postcode" size="15" />
<br />
<form method="post" action="uploads folder on server (path)" enctype="multipart/form-data">
Please specify a file, or a set of files:<br />
<br />
<input type="submit" name="browse" value="browse" />
<input type="text" name="browse" id="browse" size="20" />
<br />
<br />
<input type="submit" name="Submit" value="upload" />
</form>
<input type="submit" name="Submit" value="go" />
</form>

 

I know this is incorrect particularly the "browse" button, then the upload. Do i send the image straight to the server some way here? OR do i use an additional php script to send it off? either way i need to have the image sent WITH all the other information in the form to the database, then have that info displayed- i'll figure out that at a later date.

 

Can i send all the data in one? images with all other fields? just thought i'd take a minute out and ask you lot before i further confuse myself. Thank you for your help so far :)

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.