note 47723 deleted from features.file-upload by betz

From: Date: Fri, 26 Nov 2004 17:37:50 +0000
Subject: note 47723 deleted from features.file-upload by betz
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-81070@lists.php.net to get a copy of this message
Note Submitter: mxc at moozeek dot com ---- For newbies like me who have problems getting the file upload to work I would like to suggest the following code which uploads and changes the file permissions so the file can be accessed and used after uploading.There is no error checking but its easily added. This is just a copy paste and WORK! code snippet. Hope it saves some the hours I spendt finding this out!! ;-) <?php // Write the name of the directory you are uploading to $uploaddir = "../images"; // Then allow the file to be read after uploading! $filename = ($_FILES['file']['tmp_name']); chmod($filename, 0644); // Upload if(is_uploaded_file($_FILES['file']['tmp_name'])) { move_uploaded_file($_FILES['file']['tmp_name'], $uploaddir.'/'.$_FILES['file']['name']); } //Do something after file is uploaded // For example go to a page with a success message like here or just use print() to write something $updateGoTo = "image-success.php"; if (isset($_SERVER['QUERY_STRING'])) { $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?"; $updateGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $updateGoTo)); ?> ---- Reason: bad code

« previous php.notes (#81070) next »