Jump to content

Search the Community

Showing results for tags 'upload php help function'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 1 result

  1. here are 2 functions : this is called upon like upfile('foto1',$_SESSION['userid']) function upfile($file,$path){ $allowedExts = array("jpg", "jpeg", "gif", "png"); $extension = end(explode(".", $_FILES[$file]["name"])); if ((($_FILES[$file]["type"] == "image/gif") || ($_FILES[$file]["type"] == "image/jpeg") || ($_FILES[$file]["type"] == "image/png") || ($_FILES[$file]["type"] == "image/pjpeg")) && ($_FILES[$file]["size"] < 2000000) && in_array($extension, $allowedExts)) { if ($_FILES[$file]["error"] > 0) { echo "Return Code: " . $_FILES[$file]["error"] . "<br />"; } else { echo "Upload: " . $_FILES[$file]["name"] . "<br />"; echo "Type: " . $_FILES[$file]["type"] . "<br />"; echo "Size: " . ($_FILES[$file]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES[$file]["tmp_name"] . "<br />"; if (file_exists("usrpics/".$path .'/'. $_FILES[$file]["name"])) { echo $_FILES[$file]["name"] . " already exists. "; } else { move_uploaded_file($_FILES[$file]["tmp_name"], "usrpics/".$path.'/'. $_FILES[$file]["name"]); echo "Stored in: " . "usrpics/" .$path. $_FILES[$file]["name"]; } } } else { echo "Invalid file"; } $_SESSION['path'] ='usrpics/'.$path.'/'.$_FILES["name"] ; return TRUE ; } upload('foto1',$_SESSION['userid']) function upload($file_id,$folder) { $types="jpg,png,gif,jpeg"; $folder = 'usrpics/'.$folder ; if(!$_FILES[$file_id]['name']) return array('','No file specified'); $file_title = $_FILES[$file_id]['name']; //Get file extension $ext_arr = split("\.",basename($file_title)); $ext = strtolower($ext_arr[count($ext_arr)-1]); //Get the last extension //Not really uniqe - but for all practical reasons, it is $uniqer = substr(md5(uniqid(rand(),1)),0,5); $file_name = $uniqer . '_' . $file_title;//Get Unique Name $all_types = explode(",",strtolower($types)); if($types) { if(in_array($ext,$all_types)); else { $result = "'".$_FILES[$file_id]['name']."' is not a valid file."; //Show error if any. return array('',$result); } } //Where the file must be uploaded to if($folder) $folder .= '/';//Add a '/' at the end of the folder $uploadfile = $folder . $file_name; $result = ''; //Move the file from the stored location to the new location if (!move_uploaded_file($_FILES[$file_id]['tmp_name'], $uploadfile)) { $result = "Cannot upload the file '".$_FILES[$file_id]['name']."'"; //Show error if any. if(!file_exists($folder)) { $result .= " : Folder don't exist."; } elseif(!is_writable($folder)) { $result .= " : Folder not writable."; } elseif(!is_writable($uploadfile)) { $result .= " : File not writable."; } $file_name = ''; } else { if(!$_FILES[$file_id]['size']) { //Check if the file is made @unlink($uploadfile);//Delete the Empty file $file_name = ''; $result = "Empty file found - please use a valid file."; //Show the error message } else { chmod($uploadfile,0777);//Make it universally writable. } } return array($file_name,$result); } the first one returnsvthe route /usrpics/ but lacks the filename and extension, but always prints out img error, regardless of the picture the second one doesnt do anything. it must be a function, it needs to process several photos wich fields are called fotoX(1,2,3,and so on) i just can't figure out what is wrong with these 2 functions. i'd be really grateful if you could tell me what is wrong. PS: im only using 1 function at a time.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.