arden Posted May 4, 2010 Share Posted May 4, 2010 Hi..im a trainee in php..can any1 give me or tell me a sample script for uploading images in php.i just cant get how thehttp://w3schools.com/php/php_file_upload.aspworks.i mean..another sample pls?..thanks.. Link to comment Share on other sites More sharing options...
arden Posted May 4, 2010 Author Share Posted May 4, 2010 function getFtype($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; can any1 explain me this part?.. Link to comment Share on other sites More sharing options...
Synook Posted May 4, 2010 Share Posted May 4, 2010 That function just attempts to determine the file's content-type using its extension. Link to comment Share on other sites More sharing options...
arden Posted May 4, 2010 Author Share Posted May 4, 2010 That function just attempts to determine the file's content-type using its extension.thanks synook..btw..can you help me with this code?..<?phpdefine ("MAX_SIZE","100"); function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext;}$errors=0;if(isset($_POST['Submit'])) { $image=$_FILES['image']['name'];if ($image) { $filename = stripslashes($_FILES['image']['name']); $ftype = getExtension($filename); $ftype = strtolower($ftype);if (($ftype != "jpg") && ($ftype != "jpeg") && ($ftype != "png") && ($ftype != "gif")) { echo '<h1>Unknown extension!</h1>'; $errors=1;}else{$size=filesize($_FILES['image']['tmp_name']);if ($size > MAX_SIZE*1024){ echo '<h1>You have exceeded the size limit!</h1>'; $errors=1;}$image_name= time().'.'.$ftype; // IWANT TO CHANGE THIS IMAGE NAME, HOW?$newname="images/".$image_name;$copied = copy($_FILES['image']['tmp_name'], $newname);if (!$copied) { echo '<h1>Copy unsuccessfull!</h1>'; $errors=1;}}}} if(isset($_POST['Submit']) && !$errors) { echo "<h1>Image Uploaded!</h1>"; } ?><form name="newad" method="post" enctype="multipart/form-data" action=""><br/><table> <tr><td><input type="file" name="image"></td></tr> <tr><td><input name="Submit" type="submit" value="Upload image"></td></tr> </table> </form> I want to change the $image_name = time().'.'.$ftype;when i change it to $image_name = 'upload.'.'.$ftype;it OVERWRITES the first image that i uploaded.hope u get what i mean.thanks.. Link to comment Share on other sites More sharing options...
Synook Posted May 4, 2010 Share Posted May 4, 2010 That's because the name never changes. You need to have some sort of unique identifier (e.g. the timestamp in the original code) so the filenames are always different. Link to comment Share on other sites More sharing options...
arden Posted May 4, 2010 Author Share Posted May 4, 2010 now a new problem comes..how can i save or insert or upload an image to mysql using PHP?.. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.