Betty_S Posted February 12, 2007 Share Posted February 12, 2007 Hallo everyone! I wont to add php/html code which can do that: Let the user choose and upload a file (an image), save the file on the server and store its location into a mysql table. If you have an example code or a link that would be super! I know how to handle the html part but I have no idea whatsoever what to do with the path I get from the user! Please help me. Thanks. Link to comment https://forums.phpfreaks.com/topic/38151-how-to-upload-an-image-save-it-on-the-server-and-store-its-location-into-a-mysq/ Share on other sites More sharing options...
JJohnsenDK Posted February 12, 2007 Share Posted February 12, 2007 Here's a script where you can upload images to a folder, you just need to add the mysql part: <?php // ============== // Configuration // ============== $uploaddir = "uploads"; // Where you want the files to upload to - Important: Make sure this folders permissions is 0777! $allowed_ext = "jpg, gif, png, pdf"; // These are the allowed extensions of the files that are uploaded $max_size = "50000"; // 50000 is the same as 50kb $max_height = "100"; // This is in pixels - Leave this field empty if you don't want to upload images $max_width = "100"; // This is in pixels - Leave this field empty if you don't want to upload images // Check Entension $extension = pathinfo($_FILES['file']['name']); $extension = $extension[extension]; $allowed_paths = explode(", ", $allowed_ext); for($i = 0; $i < count($allowed_paths); $i++) { if ($allowed_paths[$i] == "$extension") { $ok = "1"; } } // Check File Size if ($ok == "1") { if($_FILES['file']['size'] > $max_size) { print "File size is too big!"; exit; } // Check Height & Width if ($max_width && $max_height) { list($width, $height, $type, $w) = getimagesize($_FILES['file']['tmp_name']); if($width > $max_width || $height > $max_height) { print "File height and/or width are too big!"; exit; } } // The Upload Part if(is_uploaded_file($_FILES['file']['tmp_name'])) { move_uploaded_file($_FILES['file']['tmp_name'],$uploaddir.'/'.$_FILES['file']['name']); } print "Your file has been uploaded successfully! Yay!"; } else { print "Incorrect file extension!"; } ?> Enjoy Link to comment https://forums.phpfreaks.com/topic/38151-how-to-upload-an-image-save-it-on-the-server-and-store-its-location-into-a-mysq/#findComment-182627 Share on other sites More sharing options...
jaikar Posted February 12, 2007 Share Posted February 12, 2007 this may be use full to you ...... for($i=1;$i<=5;$i++) { if($_FILES["file$i"]['type'] != "") { $filename = $_FILES["file$i"]; $filename = copy($filename, "../gallery/$dir_name/small/"); $SQLQuery = "INSERT INTO files_pg (file_name, directory_id, directory_name) VALUES ('$filename', $dir_id, '$dir_name')"; mysql_query($SQLQuery); } ~J Link to comment https://forums.phpfreaks.com/topic/38151-how-to-upload-an-image-save-it-on-the-server-and-store-its-location-into-a-mysq/#findComment-182644 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.