Jump to content

Uploading image to mysql error


tecmeister

Recommended Posts

Hi Everyone,

 

I have just follow a tutorial and now I'm getting a error:

Warning: fopen(file_upload) [function.fopen]: failed to open stream: No such file or directory in C:\wamp\www\php Sandbox\cpanel\include\profile_update.php on line 122

Warning: fread(): supplied argument is not a valid stream resource in C:\wamp\www\php Sandbox\cpanel\include\profile_update.php on line 123

 

This is the script that I have got from the tutorial that I've used

<?php
	$max_file_size = 10485760;
?>
		<form action="<?php $_SERVER['PHP_SELF']?>?complete_new_project" enctype="multipart/form-data" method="post">
            <table align="center" style="border: 1px #ccc solid; margin-top: 10px">
            <tr>
            	<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_file_size ?>" />
                <td>Upload Image:</td>
                <td><input type="file" name="file_upload" /></td>
            </tr>
            <tr>
                <td>Title:</td>
                <td><input type="text" name="title" style=" width: 300px" /></td>
            </tr>
            <tr>
                <td>Data:</td>
                <td><textarea rows="10" cols="70" name="data"></textarea></td>
            </tr>
            <tr>
            	<td></td>
                <td align="center"><input type="submit" value="Add New Project" name="complete"/></td>
            </tr>
            </table>
            </form>
<?php 
	}
	if(isset($_GET['complete_new_project']))
	{
		$title = $_POST['title'];
		$data = $_POST['data'];
		$date = date('l jS M Y h:i:s');
		move_uploaded_file($_FILES['file_upload']['tmp_name'],"latest.jpg");
		$instr = fopen("file_upload","r");
		$image = addslashes(fread($instr, filesize("latest.jpg")));
		if(strlen($instr) < 10485760)
		{
			mysql_query("INSERT INTO project (title, data, date, image)
						VALUES ('$title', '$data', '$date', '$image')");

		}
		else
		{
			echo 'Image to large';
		}
	}
?>

 

If you find the error please will you be able to explain where I have gone wrong.

 

Thanks,

 

tecmeister.

Link to comment
https://forums.phpfreaks.com/topic/152607-uploading-image-to-mysql-error/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.