Status
Not open for further replies.

Chris2k

Banned
Banned
901
2009
17
0
Hi, need help wit this code, well just too display bk to da end user:

PHP:
    elseif ($_POST['remoteUpload']) {
        
    $urls = explode("\n", $_POST['remoteimage']);
    $imgarray = array();
    foreach ($urls as $url)
    {
        $url = trim($url);
        $imgname = basename($url);
        $localimg = $uploadDir .'/'. $imgname;
        $img = file_get_contents($url);
        file_put_contents($localimg, $img);
        $url = $baseurl . $imgname;
        echo "<div align='center'>You've just successfully uploaded $img.</div>
        
        <div align='center'><a href='$img'><img src='$img' alt='Uploaded image'></a></div>
        
        <div align='center'>Direct Image Links</div>
        
        <p align='center'>URL: <input tabindex='1' value='$siteURL/$uploadDir/$ig' onclick='this.focus();this.select();' /></p>
        
        <p align='center'>HTML: <input tabindex='2' value='&lt;a href=&quot;$siteURL/$uploadDir/$img&quot;&gt;&lt;img src=&quot;$siteURL/$uploadDir/$img&quot; border=&quot;0&quot;&gt;&lt;/a&gt;' onclick='this.focus();this.select();' /></p>";
    }
    }

this is wot im getting, all unusual characters.

any help?
 
23 comments
Edit: hold on i get what u mean i will post in a moment

try this

PHP:
    elseif ($_POST['remoteUpload']) {
        
    $urls = explode("\n", $_POST['remoteimage']);
    $imgarray = array();
    foreach ($urls as $url)
    {
        $url = trim($url);
        $imgname = basename($url);
        $localimg = $uploadDir .'/'. $imgname;
        $img = file_get_contents($url);
        file_put_contents($localimg, $img);
        $url = $baseurl . $imgname;
        echo "<div align='center'>You've just successfully uploaded $img.</div>
        
        <div align='center'><a href='$img'><img src='$img' alt='Uploaded image'></a></div>
        
        <div align='center'>Direct Image Links</div>
        
        <p align='center'>URL: <input tabindex='1' value='$siteURL/$uploadDir/$ig' onclick='this.focus();this.select();' /></p>
        
        <p align='center'>HTML: <input tabindex='2' value='".htmlspecialchars_decode("<a href=\"$siteURL/$uploadDir/$img\"><img src=\"$siteURL/$uploadDir/$img\" border=\"0\"></a>")."' onclick='this.focus();this.select();' /></p>";
    }
    }
 
Last edited:
uhm i thought you was getting html characters, seems you are outputting image itself, change this
$siteURL/$uploadDir/$img
to
$siteURL/$uploadDir/$imgname

change all $img to $imgname where you are echoing
PHP:
 echo "<div align='center'>You've just successfully uploaded $imgname.</div>
        
        <div align='center'><a href='$imgname'><img src='$imgname' alt='Uploaded image'></a></div>
        
        <div align='center'>Direct Image Links</div>
        
        <p align='center'>URL: <input tabindex='1' value='$siteURL/$uploadDir/$imgname' onclick='this.focus();this.select();' /></p>
        
        <p align='center'>HTML: <input tabindex='2' value='".htmlspecialchars_decode("<a href=\"$siteURL/$uploadDir/$imgname\"><img src=\"$siteURL/$uploadDir/$imgname\" border=\"0\"></a>")."' onclick='this.focus();this.select();' /></p>";
    }
 
Actually, the code mRaza gave should fix the main problem

But theres a problem in that:

PHP:
<img src='$imgname' alt='Uploaded image'></a>
That will link to the imagename which will not show you the image

PHP:
if ($_POST['remoteUpload']) {
        
    $urls = explode("\n", $_POST['remoteimage']);
    $imgarray = array();
    foreach ($urls as $url)
    {
        $url = trim($url);
        $imgname = basename($url);
        $localimg = $uploadDir .'/'. $imgname;
        $img = file_get_contents($url);
        file_put_contents($localimg, $img);
        $url = $baseurl . $imgname;
        echo "<div align='center'>You've just successfully uploaded $imgname.</div>
        
        <div align='center'><a href='$imgname'><img src='$localimg' alt='Uploaded image'></a></div>
        
        <div align='center'>Direct Image Links</div>
        
        <p align='center'>URL: <input tabindex='1' value='$siteURL/$uploadDir/$ig' onclick='this.focus();this.select();' /></p>
        
        <p align='center'>HTML: <input tabindex='2' value='".htmlspecialchars_decode("<a href=\"$siteURL/$uploadDir/$imgname\"><img src=\"$siteURL/$uploadDir/$imgname\" border=\"0\"></a>")."' onclick='this.focus();this.select();' /></p>";
    }
    }

8e94543a.png
 
Thanks guys, working fab...

now do u no how to rename to each image to trhe time UTC as i have for local files..

mRaza and Soft2050 pm me ur paypal id's, i wanna send 5$ each for tha help.
 
mRaza i no how to do de name, as i done it for local files tht r uploaded but where to put in my code and to wich variable.
 
PHP:
        $imgname = basename($url);
        $localimg = $uploadDir .'/'. $imgname;
        $img = file_get_contents($url);
        file_put_contents($localimg, $img)

to

PHP:
        $imgname = basename($url);
        $localimg = $uploadDir .'/'. $imgname;
        $img = file_get_contents($url);
        file_put_contents($localimg, $img);

        $timestamp = time();
        $newname = $timestamp.$imgname;
        $newImage = $uploadDir .'/'.$newname;
        rename($localimg, $newImage);
 
Last edited:
sent donation........

ive got an error now,


Notice: Undefined index: localUpload in C:\wamp\www\includes\imageupload.php on line 5

after test

heres my full code
PHP:
    <?php
    
    include('imagecfg.php');
    
    if ($_POST['localUpload']) {
        
        $name = $_FILES['imagefile']['name']; //file name
        $type = $_FILES['imagefile']['type']; // type of file
        $size = $_FILES['imagefile']['size']; //size of the mage in bytes
        $tmp_name = $_FILES['imagefile']['tmp_name']; //temp file name and location
        $ext = substr($name, strrpos($name, '.')); //grab file extension
        
        // Requirements
        $dimension = getimagesize($tmp_name);
        $width = $dimension[0];
        $height = $dimension[1];

        // get the extension of the file in a lower case format
         $ext = strtolower($ext);

    if (array($type, $allowed) && ($maxfileSize) && ( $width < $maxWidth && $height < $maxHeight )) {
        $name = time().''.$ext; //we will give an unique name, for example the time in unix time format 
        move_uploaded_file($tmp_name, $uploadDir.'/'.$name); // upload the image, eventually i want to force the image on server to use my preferred file type
        
        echo "
        <div align='center'>You've just successfully uploaded $name with the following specifications $size bytes and $width x $height px</div>
        
        <div align='center'><a href='$uploadDir/$name'><img src='$uploadDir/$name' alt='Uploaded image'></a></div>
        
        <div align='center'>Direct Image Links</div>
        
        <p align='center'>URL: <input tabindex='1' value='$siteURL/$uploadDir/$name' onclick='this.focus();this.select();' /></p>
        
        <p align='center'>HTML: <input tabindex='2' value='&lt;a href=&quot;$siteURL/$uploadDir/$name&quot;&gt;&lt;img src=&quot;$siteURL/$uploadDir/$name&quot; border=&quot;0&quot;&gt;&lt;/a&gt;' onclick='this.focus();this.select();' /></p>";
        
    }
    else
        echo "<p>You have submitted an invalid extension/larger file size than we accept or the dimensions are too big.</p>";

    } // < attempting a local upload and all checks.
    elseif ($_POST['remoteUpload']) {
        
    $urls = explode("\n", $_POST['remoteimage']);
    $imgarray = array();

    foreach ($urls as $url) {

        $imgname = basename($url);
        $localimg = $uploadDir .'/'. $imgname;
        $img = file_get_contents($url);
        file_put_contents($localimg, $img);

        $timestamp = time();
        $newname = $timestamp.$imgname;
        $newImage = $uploadDir .'/'.$newname;
        rename($localimg, $newImage);  
            
            echo "<div align='center'>You've just successfully uploaded $newname.</div>
            <div align='center'><a href='$uploadDir/$newname'><img src='$uploadDir/$newname' alt='Uploaded image'></a></div>
            <div align='center'>Direct Image Links</div>
            <p align='center'>URL: <input tabindex='1' value='$siteURL/$uploadDir/$newname' onclick='this.focus();this.select();' /></p>
            <p align='center'>HTML: <input tabindex='2' value='".htmlspecialchars_decode("<a href=\"$siteURL/$uploadDir/$newname\"><img src=\"$siteURL/$uploadDir/$newname\" border=\"0\"></a>")."' onclick='this.focus();this.select();' /></p>";
    }
    }  
?>
 
replace this
if ($_POST['localUpload']) {
with
if (isset($_POST['localUpload'])) {

and

elseif ($_POST['remoteUpload']) {
to
elseif (isset($_POST['remoteUpload'])) {

also make sure to check file types for security reasons.
 
i did tht bro at 1st nd then removed it, because:

Code:
[B]Notice[/B]:  Undefined index: imagefile in [B]C:\wamp\www\includes\imageupload.php[/B] on line [B]7[/B]

[B]Notice[/B]:  Undefined index: imagefile in [B]C:\wamp\www\includes\imageupload.php[/B] on line [B]8[/B]

[B]Notice[/B]:  Undefined index: imagefile in [B]C:\wamp\www\includes\imageupload.php[/B] on line [B]9[/B]

[B]Notice[/B]:  Undefined index: imagefile in [B]C:\wamp\www\includes\imageupload.php[/B] on line [B]10[/B]

[B]Warning[/B]:  getimagesize() [[URL="http://localhost/function.getimagesize"]function.getimagesize[/URL]]: Filename cannot be empty in [B]C:\wamp\www\includes\imageupload.php[/B] on line [B]14[/B]


d'ya no how to fix?
 
here da 2 forms

PHP:
<div id="local">
    <h2>Choose a file, by browsing your PC.</h2>
        <form method='POST' enctype='multipart/form-data' id='uploadLocalForm'>
        <input type="hidden" name="p" value="1" />

        <input type='file' name='imagefile' size="65" value="Click to browse..." /><br>
    
        <input type='submit' name='localUpload' value='Upload' /><br>
        </form></div>

<div id="remote">
    <h2>Find an image on the web and paste the URL here.</h2>
        <form method='POST' enctype='multipart/form-data' name='uploadForm' id='form1'>
        <input type="hidden" name="p" value="1" />

        <input name='remoteimage' size="65" /><br>
    
        <input type='submit' name='remoteUpload' value='Upload' />
        </form></div>
]
 
Status
Not open for further replies.
Back
Top