₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,325,000 members, 8,419,869 topics. Date: Thursday, 04 June 2026 at 05:21 AM

Toggle theme

Php Help - Webmasters - Nairaland

Nairaland ForumScience/TechnologyWebmastersPhp Help (895 Views)

1 Reply (Go Down)

Php Help by robola(op): 4:30pm On Nov 25, 2010
hello all, pls i need php code to upload pic files. somebody help
Re: Php Help by lojik(m): 9:46pm On Nov 25, 2010
############################################################
## this function upload a file and return its path or return the error detail ##
## $fieldname=name of the file field from html form ##
## $allowedExt=file extension allowed 4 upload e.g $allowedExt=".jpe.jpeg.png.gif"; ##
## $uploadsDirectory=path to folder where file should go ##
#############################################################

function uploadNewFile($fieldname, $allowedExt, $uploadsDirectory){
// possible PHP upload errors
$errors = array(1 => 'Selected file is too large!',//php.ini max file size exceeded!
2 => 'Selected file is too large!',//html form max file size exceeded!
3 => 'Incomplete file upload!',//file upload was only partial!
4 => 'No file was selected!');


if(!($_FILES[$fieldname]['error'] == 0)) return 'Error - '.$errors[$_FILES[$fieldname]['error']];// check for PHP's built-in uploading errors

// check that the file we are working on really was the subject of an HTTP upload
if(!(@is_uploaded_file($_FILES[$fieldname]['tmp_name']))) return 'Error - File is not an HTTP upload!';

//Check if its in the allowed extension list
$ext = $this->getExtension($_FILES[$fieldname]['name']);
$pos = strripos($allowedExt,$ext);
if ($pos === false) return 'Error - Invalid file type!';

//create unique filename
$now = time();
while(file_exists($uploadFilename = $uploadsDirectory.$now.'-'.$_FILES[$fieldname]['name'])){
$now++;
}

// now let's move the file to its final location
if(!(move_uploaded_file($_FILES[$fieldname]['tmp_name'], $uploadFilename))) return 'Error - Unable to move file uploaded file';
else return $uploadFilename; //file upload successful
}




Usage:
$path_to_uploaded file = uploadNewFile("passport", ".jpg.jpeg.png.gif.bmp", "images/members/passports/"wink;
if(strripos($path_to_uploaded file,"Error"wink {
//file upload failed
die($path_to_uploaded file);
} else {
//upload successful
// save $path_to_uploaded file in database
};


This is my multipupose upload function. i hope someone can give u a simpler one.
Re: Php Help by yawatide(f): 10:11pm On Nov 25, 2010
http://www.google.com/#sclient=psy&hl=en&q=php%20picture%20upload%20script&aq=1&aqi=g4g-o1&aql=&oq=&gs_rfai=&pbx=1&fp=573da4ec7e15bdf2&pf=p
Re: Php Help by Nobody: 5:24pm On Nov 26, 2010
undecided why not just read PHP Tutorials or get from Google saves time waiting for response
1 Reply

Php HelpSocket Programming In Php Help Hints ?Email Retrieval With Php - Help Anyone?234

Dual Core Oya Where You DeyHow Do I Remove Extension From Urls.Buy All Nigerian Traffic