Jump to content

need help with image uploader


RadiationHazard

Recommended Posts

so i haven't really started learning php that much i only know the very basics and i'm about to start learning i hope if i have the time

but i was wondering if someone could add whatever this page needs to make it do what i want. right now what it does is it just gives the url to the image. what i want it to do is to give the url to the image the html code for the image and if it's not to much the form code for the image also i would like it to when you click in the box with the codes if it would automatically copy. if anyone could pleasee do this for me a would be very greatful!

 

here is the code:

<?php

// The Temporary Directory where the file is uploaded too
// THIS DIRECTORY MUST EXIST!
$target_path = "temp/";

## SET YOUR WEBSITE URL PATH HERE.
### TO BE USED FOR THE TEXTAREA OUTPUT.
$siteurl = "http://localhost/image_uploader";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) 
{


// The Output page.
echo '
<img src="'.$target_path.'" />
<br />
<textarea COLS=60>'.$siteurl.$target_path.'</textarea>';


}

 else
{
// What to say if there is an error.
echo "There was an error uploading the file.<br />Most likely, your file is too big.";
}

 

 

Link to comment
Share on other sites

i dont know what you meant by "i would like it to when you click in the box with the codes if it would automatically copy"? but i wrote this for the rest of your question

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">

<html>
<head>
    <title>Image uploader</title>
</head>

<body>
<?php

// The Temporary Directory where the file is uploaded too
// THIS DIRECTORY MUST EXIST!
$target_path = "temp/";

## SET YOUR WEBSITE URL PATH HERE.
### TO BE USED FOR THE TEXTAREA OUTPUT.
$siteurl = "http://localhost/image_uploader";

$target_path = $target_path . basename($_FILES['uploadedfile']['name']);

if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {


    // The Output page.
    echo "
<img src=\"$target_path\" />
<br />
<textarea COLS=\"60\">{$siteurl}/{$target_path}</textarea>";


} else {
    // What to say if there is an error.
    echo "There was an error uploading the file.<br />Most likely, your file is too big.";
}

?>
    <form action="http://localhost/image_uploader/index.php" method="post" enctype="multipart/form-data">
        <table>
            <tr>
                <td>File:<input type="file" name="uploadedfile"></td>
            </tr>

            <tr>
                <td><input type="submit" value="Upload"></td>
            </tr>
        </table>
    </form>
</body>
</html>

It should work.

 

Scott.

 

Link to comment
Share on other sites

thank your for the try. but maybe i was unclear or maybe it's just not working right. so i will try to explain myself better

I am trying to make a image uploader similar to tinypic.com right now it already gives me the direct link when i upload it the only other thing that i want is for it to also put it into an html code for sites and stuff

Link to comment
Share on other sites

if someone could please hurry and help i'm really exited about telling some people about my site. but i don't want to start telling people about it until i get it the way i want it. one more thing that i've noticed is if the file you upload is not named like image.jpg and it's just named image it won't still supply a working link to it. is there anyway you can set the code to where if it doesn't have .jpg or .gif or w/e that it will add the file type?

Link to comment
Share on other sites

and just incase you're still not understanding what it is that i'm wanting i want this...

 

php.jpg

 

html code:

<a href="http://jordan.is-a-geek.com/" target="_blank"><img src="http://jordan.is-a-geek.com/image_uploader//temp/php.jpg" border="0" alt="Image hosting by Jordan.is-a-geek.com"></a>

 

Direct Link:

http://jordan.is-a-geek.com/image_uploader//temp/php.jpg

 

i wanting it to be something like that

Link to comment
Share on other sites

sorry for delay, watched a movie :P

 

this is the same principle:

 

just echo out the html you want with htmlentities so the browser does not parse it; eg:

 

<a href="http://jordan.is-a-geek.com/" target="_blank"><img src="http://jordan.is-a-geek.com/image_uploader//temp/php.jpg" border="0" alt="Image hosting by Jordan.is-a-geek.com"></a>

 

echo "
<img src=\"$target_path\" /><br />"
.htmlentities("HTML = <a href=\"http://jordan.is-a-geek.com/\" target=\"_blank\"><img src=\"$siteurl/$target_path\" /></a>")
."<br /><br /><textarea COLS=\"60\">{$siteurl}/{$target_path}</textarea>";

 

hope this helps,

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.