473,397 Members | 2,056 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

uploading an image file

194 100+
hi every body,

i am using the following code to upload an image. it directly jumps to the error message please tell me what im doing wrong here.

Expand|Select|Wrap|Line Numbers
  1.  
  2. <form name="myform" enctype="multipart/form-data" method="post" action="">
  3. Upload Album/Artist Image : <input type="file" name="imguploader"> <br />
  4. <input type="submit" value="uploadnow" name="yes" />
  5. </form>
  6.  
  7. <?php
  8. extract($_POST);
  9.  
  10. if($yes){
  11.         $img_types2 = array("image/gif","image/pjpeg","image/jpeg","image/jpg","image/bmp","image/png");
  12.  
  13.         if($_FILES["imguploader"]["name"]!="" && in_array($_FILES["imguploader"]["type"],$img_types2)){
  14.         $img2 = time()."_".str_replace(" ","_",$_FILES["imguploader"]["name"]);
  15.         move_uploaded_file($_FILES["imguploader"]["tmp_name"],"images/".$img2);
  16.     } else {
  17.         echo "Image file not uploaded successfully.";
  18.     }
  19.  
  20. }
  21. ?>
  22.  

this is displaying "Image file nto uploaded successfully". please tell me whats wrong with it.
Apr 15 '09 #1
6 1810
Dormilich
8,658 Expert Mod 8TB
instead of $yes I'd go for isset($_POST['yes'])
Apr 15 '09 #2
mfaisalwarraich
194 100+
thanx dormilich its working now :). but what was the reason for not working with extract($_POST)? cuz this is a very simple example. if im working on a more complex site where i have variables using extract($_POST) then i will not be able to upload the image file using this method? please tell me so i can know the concept of this. thank u again
Apr 15 '09 #3
Dormilich
8,658 Expert Mod 8TB
I don't know, but I consider that approach highly insecure (you may have unwanted (i.e. user injected) (global) variables going round which may serve to hack your script).

@mfaisalwarraich
you have to know the variable's name in any case, so I see no problem. further, you can do this with isset:
Expand|Select|Wrap|Line Numbers
  1. if (isset($var1, $var2, $var3)) { … }
  2. // returns true only if all variables exist
Apr 15 '09 #4
mfaisalwarraich
194 100+
ok thank u once again. this is very useful help.
Apr 15 '09 #5
Markus
6,050 Expert 4TB
There's an extra ending brace in there, too. Line 20.
Apr 15 '09 #6
mfaisalwarraich
194 100+
yes thank you its eliminated markus :)
Apr 15 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: ok | last post by:
Hello, Q: How do I get image width and height before uploading an image? This because, I want to restrict people uploading huge files. Thanks in advance
7
by: lion | last post by:
I get these errors when uploading images via a web page: (the page still uploads the images but reports these errors?) Warning: fopen(D:\php\uploadtemp\php1FC7.tmp) : failed to create stream: No...
1
by: JonChart | last post by:
Hi all, I would like to know ho to validate a file name when uploading via asp and whether or not this can be validated with javascript? I need to upload 2 images and the file names must be...
7
by: Roger Withnell | last post by:
I would like to check that an image file, selected by a user using fileUpload, is within certain parameters (width, height, filesize) and to display the image file so that the user can see the...
10
by: John Smith | last post by:
I know that uploading an image to a database has been covered, oh, about 3 trillion times. However, I haven't found anything covering uploading to a MySQL database with .net. Please don't...
0
by: Alex | last post by:
my app was working fine in VB.NET 2003 (and framework 1.1). Now with VB.NET 2005 (framework 2.0) the uploading to an http server (ie. www.sharebigfile.com) stops with the error "The request was...
1
by: wenqiang7 | last post by:
I am encountering a very strang problem with file uploading in my ASP.Net page. When we try to upload certain file, we'll get an error msg of "Cannot find server or DNS Error". We are running...
2
by: prakharv | last post by:
Hi All, Below is the code which I am using to upload a jpeg file to the server. But the problem I am facing is that it is not copying the entire contents of the image file to the webserver and it...
44
by: badvoc | last post by:
Hi to all, Firstly I must state my knowledge of php is limited but I am a quick learner. I have taken on the task of finishing a friends website due to his untimely passing and have hit a problem...
1
pezholio
by: pezholio | last post by:
Hi, It seems that every time I put together a new script to upload a file I always have problems, here's the latest one: I've got a form with two file input fields, when I submit the form,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.