didy Posted March 1, 2008 Report Share Posted March 1, 2008 <?php // failu parbaude (extensiju parbaude + max lielums if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/jpg") || ($_FILES["file"]["type"] == "image/png") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 20000)) { // Pievienosanas DB require ($_SERVER["DOCUMENT_ROOT"]."/config/db_config.php"); $connection = @mysql_connect($db_host, $db_user, $db_password) or die ("error connecting"); mysql_select_db($db_name, $connection); $data = addslashes(fread(fopen($_FILES["file"]["type"], "r"), $_FILES["file"]["size"])); // Faila ievietosana tabula $query = mysql_query("INSERT INTO upload_img (file) VALUES ('$data')") or die("Can't Perform Query"); mysql_query($query, $connection) or die (mysql_error()); // Augsupladeta faila info (nosaukums, lielums) echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"]) . " Kb<br />"; } // Ja vails neatbilst (izvada else) else {echo "Nepareizs fails";} ?> Warning: fopen(image/png) [function.fopen]: failed to open stream: No such file or directory in E:\webroot\uploader.php on line 23 Warning: fread(): supplied argument is not a valid stream resource in E:\webroot\uploader.php on line 23 Can't Perform Query DB izveidoju tabulu upload_img CREATE TABLE `latbit_db`.`upload_img` ( `autoID` INT( 64 ) UNSIGNED NOT NULL AUTO_INCREMENT , `name` VARCHAR( 64 ) NOT NULL , `size` INT NOT NULL , `type` VARCHAR( 64 ) NOT NULL , `file` BLOB NOT NULL , PRIMARY KEY ( `autoID` ) ) ENGINE = InnoDB Kur kluda? Link to comment Share on other sites More sharing options...
bubu Posted March 1, 2008 Report Share Posted March 1, 2008 Un kas nav skaidrs? Tur tak rakstīts - "No such file or directory" un "Can't Perform Query". Jālieto ir mysql_error() fja nevis die() fja, kad notiek query kļūda. Link to comment Share on other sites More sharing options...
didy Posted March 1, 2008 Author Report Share Posted March 1, 2008 Warning: fopen(image/png) [function.fopen]: failed to open stream: No such file or directory in E:\webroot\uploader.php on line 23 Warning: fread(): supplied argument is not a valid stream resource in E:\webroot\uploader.php on line 23 Field 'name' doesn't have a default value "No such file or directory" direktorija ir! Link to comment Share on other sites More sharing options...
bubu Posted March 1, 2008 Report Share Posted March 1, 2008 Nevajag mūs te čakarēt. Saka tev, ka nav - tad nav. Vai nu fails, vai nu direktorija. Uztaisi echo tam stringam, kuru dod fopen parametrā un pats redzēsi, ka tāds fails neeksistē. Link to comment Share on other sites More sharing options...
didy Posted March 1, 2008 Author Report Share Posted March 1, 2008 $data = addslashes(fread(fopen($_FILES["file"]["type"], "r"), $_FILES["file"]["size"])); echo "Upload: " . $_FILES["file"]["name"] . "<br />"; Upload: 4.jpg Link to comment Share on other sites More sharing options...
bubu Posted March 1, 2008 Report Share Posted March 1, 2008 Pag, kur tev ir loģika - ar echo tu izdrukā $_FILES["file"]["name"], bet fopen funkcijai padod $_FILES["file"]["type"] vērtību.. Tie tak divi dažādi stringi. Tu jau liec atvērt viņam failu, kura nosaukums ir $_FILES["file"]["type"], nevis ..["name"]. Link to comment Share on other sites More sharing options...
Klez Posted March 1, 2008 Report Share Posted March 1, 2008 $query = mysql_query("INSERT INTO upload_img (file) VALUES ('$data')") or die("Can't Perform Query"); mysql_query($query, $connection) or die (mysql_error()); ko tu ar shitaam rindaam meegini panaakt? par shito jau bubu uzrakstiija .. resource fopen ( string $filename , string $mode [, bool $use_include_path [, resource $context ]] ) $data = addslashes(fread(fopen($_FILES["file"]["type"], "r"), $_FILES["file"]["size"])); Link to comment Share on other sites More sharing options...
kasisppr Posted March 3, 2008 Report Share Posted March 3, 2008 Kāpēc cilvēkiem tā patīk bāzt bildes datubāzē??? Manuprāt datubāzes tam nav paredzētas. Labāk uztaisi kādu rakstāmu folderi, tur samet bildes caur move_uploaded_file ( string filename, string destination); Pirms tam bildēm pamaini nosaukumus uz kādiem unique nosaukumiem - izmantojot kaut vai to pašu uniqid(). Savukārt datubāzē glabā informāciju par bildi - ceļu, nosaukumu, izmēru... visu, ko uzskatīsi par vajadzīgu. Link to comment Share on other sites More sharing options...
Recommended Posts