/    Sign up×
Community /Pin to ProfileBookmark

storing to db via form + optional image upload

hi experts,

i am referring to [URL=http://www.webdeveloper.com/forum/showthread.php?t=96532]this thread[/URL] by [B]bokeh[/B] entitled [B]“How to: Upload images using PHP”[/B].

i want to achieve a solution where one can add a news item to a mysql db and [B]optionally[/B] attach a picture too.

so i modified the [B]upload.form.php[/B] and added 2 more form fields: “headline” and “text”.

next i edited [B]upload.processor.php[/B] so that additionally the values of the fields “headline” and “text” as well as the location of the uploaded image on the server get stored in a mysql table.

that works perfectly as long as there is a picture attached and it doesn´t exceed the $max_file_size.

since i want to make the image upload optional i tried some [B]if-else statements in upload.processor.php[/B] to avoid getting errors when there is no pic attached.

no surprise to me that none of my attempts worked so i´m kindly asking for your help to achieve something like this:

[code=php]if (there was a picture selected in upload.form.php) {
// …do what bokeh´s original script does (including error checking) + store info in db…
} else {
// …only store the values of the fields “headline” and “text” into the db and ignore that an image is missing…[/code]

my problem is to find the right [B]if-statement[/B]. i tried [B]if (strlen($_FILES[$fieldname][‘tmp_name’]) > 1)[/B] but then i don´t get any error msg when max file size is exceeded.

any ideas?

thanks in advance,
jogol

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@bokehMar 08.2006 — [code=php]if($_FILES[$fieldname]['error'] !== 0)
{
// no image was uploaded
}[/code]
Copy linkTweet thisAlerts:
@jogolauthorMar 08.2006 — thanks ?
Copy linkTweet thisAlerts:
@binhausAug 14.2006 — use my solution... i thinh that the best way.. affter i read many upload image php + image name stored in data mysql

notices that i have ask for some one help me here for that .. but mostly no one find out my problems in my scripts.. at the end i found my selft ( that stupid bugs) i just forget to put the ( enctype="multipart/form-data" ) in the form ..


read my post and put this one in.. all will work..

explain : you can call the funtion uploadimg() any time .. like $nameimagewillstoreindata=@uploadimg() then you can store the $nameimagewillstoreindata affter you call it.. .. the convenian is this php script only one file.. http://www.webdeveloper.com/forum/showthread.php?t=117029


now i trying to use it as muti uploader with ajax... if anyone have solution please help me..thanks

ragards..
×

Success!

Help @jogol 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.15,
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,
)...