Status
Not open for further replies.
i tested ur above code but it works fine here, post your imageupload.php file here.
also ur form is in same file or other post that as well,

also ur action attribute is missing in form, not a good practice.
 
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.

sorry try this 1, imageupload.php: http://paste2.org/p/1512203

The below code should work with remote upload and file upload both of them. Here you go with the whole code:

Paste bin:


Or

PHP:
<?php

//uncomment this when u have imagecfg.php

// include('imagecfg.php');

$siteURL = "http://localhost";
$uploadDir = "images";
    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 = strtotime(gmdate("M d Y H:i:s", 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 (isset($_POST['remoteUpload'])) {
        
    $urls = explode("\n", $_POST['remoteimage']);
    $imgarray = array();
    foreach ($urls as $url)
    {
        $url = trim($url);
        $imgname = strtotime(gmdate("M d Y H:i:s", time())) . '-' . 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='$localimg'><img src='$localimg' alt='Uploaded image'></a></div>
        
        <div align='center'>Direct Image Links</div>
        
        <p align='center'>URL: <input tabindex='1' value='$siteURL/$localimg' onclick='this.focus();this.select();' size='65' /></p>
        
        <p align='center'>HTML: <input tabindex='2' value='".htmlspecialchars_decode("<a href=\"$siteURL/$localimg\"><img src=\"$localimg\" border=\"0\"></a>")."' onclick='this.focus();this.select();' size='65' /></p>";
    }
    }  
?>
<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>

You could directly use:

PHP:
strtotime(gmdate("M d Y H:i:s", time()))

To generate time

You have a Nice idea to give filename with time so that the images doesn't gets overwrited :)

Uncomment the line that i commented since i dont have imagecfg.php

[SLIDE]http://lulzimg.com/i23/84090ea1.png[/SLIDE]
 
Status
Not open for further replies.
Back
Top