Jump to content
php.lv forumi

failed to open stream


didy

Recommended Posts

<?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

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

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

$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

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

×
×
  • Create New...