okay
for local uploading i do checks like:
as u see this if statement is doing the checks:
so can any1 tell me how/where to add for remote uploading, heres me code:
for local uploading i do checks like:
PHP:
$name = $_FILES['imagefile']['name']; //file name
$type = $_FILES['imagefile']['type']; // type of file
$size = $_FILES['imagefile']['size']; //size of the mage in bytes
$imageKB = round(($size / 1024), 2); // bytes to KB
$imageMB = round(($size / 1048576), 2); // bytes to MB
$tmp_name = $_FILES['imagefile']['tmp_name']; //temp file name and location
/* // FILE SIZES
$file_gb = round(($filesize / 1073741824), 2); // bytes to GB
// PHP does funny thing for files larger than 2GB */
$ext = substr($name, strrpos($name, '.')); //grab file extension
// Requirements
$dimension = getimagesize($tmp_name);
$width = $dimension[0]; // uploaded image width
$height = $dimension[1]; // uploaded image height
// get the extension of the file in a lower case format
$ext = strtolower($ext);
if (in_array($type, $allowed) && ($size <= $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
}
as u see this if statement is doing the checks:
PHP:
if (in_array($type, $allowed) && ($size <= $maxfileSize) && ( $width < $maxWidth && $height < $maxHeight )) {
so can any1 tell me how/where to add for remote uploading, heres me code:
PHP:
$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);
$exten = substr($url, strrpos($url, '.') + 1); // The "strrpos" approach to get the extension.
$ch = curl_init($url); // Get the filesize using curl
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$data = curl_exec($ch);
curl_close($ch);
if ($data === false) {
echo 'cURL failed';
exit;
}
$remoteSize = 'unknown';
$status = 'unknown';
if (preg_match('/^HTTP\/1\.[01] (\d\d\d)/', $data, $matches)) {
$status = (int)$matches[1];
}
if (preg_match('/Content-Length: (\d+)/', $data, $matches)) {
$remoteSize = (int)$matches[1];
}
$imageKB = round(($remoteSize / 1024), 2); // bytes to KB
$imageMB = round(($remoteSize / 1048576), 2); // bytes to MB
$newname = time().'.'.$exten; // Got the file type, works ok, not ideal way but we need to check to see its valid t ype. really should use curl.
$newImage = $uploadDir .'/'.$newname;
rename($localimg, $newImage);
}