wrathican Posted April 29, 2008 Share Posted April 29, 2008 hey. im trying to create a file upload system for images i want to upload the file to a temp dir. and then create a thumbnail and store that in a new directory then delete the old tmp dir file on success. so far i only have the file upload function. i guess i kinda need to return the destination of the file so that my thumbnail function will be able to find it. i know that the move_uploaded_file only returns false if thyere is an error. so would my code below return the newfile location on success? here is the code i have at the moment <?php $tmpImg = '../images/temp/'; $oldFile = $_FILES['uploadedfile']['tmp_name']; function uploadFile ($oldFile, $tmpDir) { //extensions array $validExt = array ('jpg', 'jpeg', 'png'); //get the file ext $ext = strrchr($oldFile, "."); //check the file ext against the array if(in_array($ext, $validExt)) { //needle is in haystack //process upload //rename the file $newName = md5(rand() * time()) . $ext; //new file dest $destFile = $tmpDir . $newName; //move the file to tmpDir $result = move_uploaded_file($oldfile, $destFile); if($result == false) { //there was an error uploading exit; }else{ //file was uploaded return $destFile; } }else{ //needle is not in haystack. exit return false; } } uploadFile($oldFile, $tmpImg); ?> Link to comment https://forums.phpfreaks.com/topic/103387-file-upload-function/ Share on other sites More sharing options...
wrathican Posted April 30, 2008 Author Share Posted April 30, 2008 any ideas? heres a newer version of the function: <?php function uploadFile ($oldFile, $tmpDir) { //extensions array $validExt = array ('jpg', 'jpeg', 'png'); //get the file ext $ext = strrchr($userFile, "."); //check the file ext against the array if(in_array($ext, $validExt)) { //needle is in haystack //process upload //rename the file $newName = md5(rand() * time()) . $ext; //new file dest $destFile = $tmpDir . $newName; //move the file to tmpDir $result = move_uploaded_file($oldfile, $destFile); if($result == false) { //there was an error uploading return false; exit; }else{ //file was uploaded return $destFile; } }else{ //needle is not in haystack. exit return false; exit; } } ?> Link to comment https://forums.phpfreaks.com/topic/103387-file-upload-function/#findComment-530185 Share on other sites More sharing options...
nadeemshafi9 Posted April 30, 2008 Share Posted April 30, 2008 use ftp functions and the gd library to upload and manipulate the image Link to comment https://forums.phpfreaks.com/topic/103387-file-upload-function/#findComment-530187 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.