i have 1500 images i want to upload to my new image upload site, it would be quite laborious to do it by hand. does anyone know of a way i can upload the folder with the pictures to my root folder then write a script that will fill the upload form on my sites main page and upload it to my database? i will pay for this help
If you can give a breakdown of how your database is set up for the files it should be possible to do this without needing to use the upload form for each
Thjis is my process.php file <?php include "header.php"; //Image Upload Script //Part of ImageHostSript. //See conf_global.php // $userfile is where the file is on the webserver $userfile = $HTTP_POST_FILES['imagefile']['tmp_name']; // $userfile is original file name $userfile_name = $HTTP_POST_FILES['imagefile']['name']; // $userfile_size is size in bytes $userfile_size = $HTTP_POST_FILES['imagefile']['size']; // $userfile_type is mime type e.g. image/gif $userfile_type = $HTTP_POST_FILES['imagefile']['type']; // $comments are the comments, but we need logic if there aren't comments. if($_POST['comments']) { $comments = $_POST['comments']; if (get_magic_quotes_gpc() == 0) { $comments = addslashes($comments); } $comments = nl2br($comments); } else { //they didn't comment $comments = 'No comment for this image'; } //Sporadic MIME-TYPES? if ($userfile_type == 'image/x-png') { $userfile_type = 'image/png'; } if ($userfile_type == 'image/pjpeg') { $userfile_type = 'image/jpeg'; } // $userfile_error is any error encountered $userfile_error = $HTTP_POST_FILES['imagefile']['error']; //PHP 4.2.0+ code ONLY. This code will not work with PHP 4.1 or less if ($userfile_error > 0) { echo 'Problem: '; switch($userfile_error) { case 1: echo 'File exceeded Maximum upload filesize'; break; case 2: echo 'File exceeded Maximum upload filesize'; break; case 3: echo 'File partially uploaded'; break; case 4: echo 'No File Uploaded'; break; } exit; } //end of code for 4.2.0+ switch($userfile_type) { case 'image/gif': break; case 'image/png': break; case 'image/jpeg': break; case 'image/bmp': echo "BMP File format not supported. Please upload a JPEG, PNG, or a GIF. Thanks. "; exit; default: echo "Problem: File is not a supported image filetype. Please upload a JPEG, PNG, or a GIF. Thanks. "; echo "<br> your file has a MIME-TYPE of $userfile_type"; exit; break; } //Lets try connecting to mySQL @ $db = mysql_pconnect($mysql['host'], $mysql['user'], $mysql['pass']); //IT"S NOT WORKING! if (!$db) { die("error"); } mysql_select_db($mysql['db']); //We need to get a date for our Database $date = time(); //Put the data there! $query = "INSERT INTO `images` ( `id` , `size` , `downloads` , `lastuse` , `type` , `comments`, `ip` , `report` ) VALUES ('', " . $userfile_size . ", '0', " . $date . ", " . '\'' . $userfile_type . '\'' . ", " . '\'' . $comments . '\'' . ", " . '\'' . $_SERVER['REMOTE_ADDR'] . '\'' . " , '' );"; //QUERY! $result = mysql_query($query); if (!$result) { die("MySQL insert error"); } $userfile_name = mysql_insert_id(); //put the file where we want it $upfile = './uploads/' . $userfile_name; //need PHP 4.0.3 if(is_uploaded_file($userfile)) { if (!move_uploaded_file($userfile, $upfile)) { echo 'Problem: Could not move file to destination directory'; exit; } } else { echo 'Problem: Possible File upload attack. Filename: '.$userfile_name; exit; } echo 'File uploaded successfully<br/><br/>'; //get current stats $query = "SELECT * FROM `stat_cache`"; $result = mysql_query($query); if (!$result) { die("MySQL Select error"); } $stat = mysql_fetch_array($result); //update statistics //files update $files = $stat['files'] + 1; $query = "UPDATE `stat_cache` SET files=" . $files . " WHERE 1"; $result = mysql_query($query); if (!$result) { die("MySQL Update error"); } //space update $totalspace = $stat['space'] + $userfile_size; $query = "UPDATE `stat_cache` SET space=" . $totalspace . " WHERE 1"; $result = mysql_query($query); if (!$result) { die("MySQL Update error"); } //1337 h4x0rs can resize everything, even though we can't outputz0rz to everything. //Resample it now! // The file $filename = $upfile; $thumb = './uploads/' . 'thumb_' . $userfile_name; // Set a maximum height and width $width = 150; $height = 150; // Get new dimensions list($width_orig, $height_orig) = getimagesize($filename); if(($width_orig < $width) && ($height_orig < $height)) { $width = $width_orig; $height = $height_orig; } else { if ($width && ($width_orig < $height_orig)) { $width = ($height / $height_orig) * $width_orig; } else { $height = ($width / $width_orig) * $height_orig; } } // Resample $image_p = imagecreatetruecolor($width, $height); if($userfile_type == 'image/jpeg') { $image = imagecreatefromjpeg($filename); } if($userfile_type == 'image/png') { $image = imagecreatefrompng($filename); } if($userfile_type == 'image/gif') { $image = imagecreatefromgif($filename); } imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); // Output if($userfile_type == 'image/jpeg') { imagejpeg($image_p, $thumb); } if($userfile_type == 'image/png' or $userfile_type == 'image/gif') { imagepng($image_p, $thumb); $userfile_type = 'image/png'; } $userfile_size = filesize($upfile); $id = $userfile_name; //Put the data there! $query = "INSERT INTO `thumbs` ( `id` , `size` , `downloads` , `lastuse` , `type` )VALUES ('$id', '$userfile_size', '0', '$date', '$userfile_type');"; //QUERY! $result = mysql_query($query); if (!$result) { die("MySQL insert error 2 " . mysql_error()); } //get current stats $query = "SELECT * FROM `stat_cache`"; $result = mysql_query($query); if (!$result) { die("MySQL Select error"); } $stat = mysql_fetch_array($result); //update statistics //space update $totalspace = $stat['space'] + $userfile_size; $query = "UPDATE `stat_cache` SET space=" . $totalspace . " WHERE 1"; $result = mysql_query($query); if (!$result) { die("MySQL Update error"); } ?> <FORM action="nowhere" method="post">
you can upload file to server and do script loop the directory, read the filename and insert to database.
i suppose you don't want to add comment for every 1000+ images right? so I can skip the comment part, right?
You could just put them all into a zip file and upload them? Then just decompress. Takes about 2 minutes.
he wants to update the sql at the same time. BTW sweetlouise, i sent a pm to you along with the file. Good Night guys