/    Sign up×
Community /Pin to ProfileBookmark

help debbugging

I’m getting this message after pressed upload button. Help please.

Array ( )
Warning: fread(): supplied argument is not a valid stream resource in C:wampwwwMyAdmintratorTempaddPhoto.php on line 7

<?php
if ($_POST[‘Submit’]) {
if ($_
POST[‘MAX_FILE_SIZE’] >= $_FILES[‘file’][‘size’]) {
print_r($_
FILES);
mysql_connect(“localhost”, “root”, “”) or die(mysql_error());
mysql_select_db(“test”);
$photo = addslashes(fread(fopen($_FILES[‘file’][‘tmp_name’], “rb”), $_FILES[‘file’][‘size’]));

$query = sprintf(“INSERT INTO image(Image, FileType) VALUES(‘%s’, ‘%s’)”, $photo, $_FILES[‘file’][‘type’]);
if (mysql_query($query)) {
$messages[] = “Your files is successfully store in database”;
} else {
$messages[]= mysql_error();
}
}
else {
$messages[]=”The file is bigger than the allowed size please resize”;
}
}

?>
<html>
<head>
<title>Add Image</title>
</head>

<body>
<?
if (isset($messages)) {
foreach ($messages as $message) {
print $message. “<br>” ;
}
}
?>
<form action=”” method=”post” enctype=”multipart/form-data” name=”form1″>
<input type=”file” name=”file”>
<input type=”hidden” name=”MAX_FILE_SIZE” value=”96000″>
<input type=”submit” name=”Submit” value=”Submit”>
</form>
</body>
</html>

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@ratcatemeNov 15.2008 — move the print_r to the top of our script rather than inside the if's

also don't rely on the MAX_FILE_SIZE from the form that is a very easy value for a user to change if they want to.

Scott.
Copy linkTweet thisAlerts:
@diltonauthorNov 18.2008 — Thanks for your help. But I tried to move Print_R on top of if and still get the same error message after I pressed upload button. Please if you've better concept to solve this problem let me know. Thanks again.
Copy linkTweet thisAlerts:
@ratcatemeNov 18.2008 — just looking on [url=http://nz.php.net/features.file-upload]php.net[/url] it says you must have the MAX_FILE_SIZE before the file input this could be causing you the problems?

try moving them around to see what happens.

Scott.
×

Success!

Help @dilton spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...