How can I upload any file type? And just display the uploaded file picture. What do I need to cut out of the following code?
-
I'm using the following code: <?php if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/xjpeg") || ($_FILES["file"]["type"] == "image/xpng") || ($_FILES["file"]["type"] == "image/png") || ($_FILES["file"]["type"] == "image/bmp") || ($_FILES["file"]["type"] == "image/jpg") || ($_FILES["file"]["type"] == "image/JPG") || ($_FILES["file"]["type"] == "image/XJPG") || ($_FILES["file"]["type"] == "image/xjpg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 40000000000000000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; include('SimpleImage.php'); $image = new SimpleImage(); $image->load('upload/' . $_FILES["file"]["name"]); $image->resizeToWidth(250); $image->save('upload/picture2.png'); print("<br><b>Congrats!</b><br><img alt='' src='upload/picture2.png' />"); } } } else { echo "Invalid file issue: " . $_FILES["file"]["error"]; } ?>
-
Answer:
Never rely on the file type information coming from the browser because it may be fake and you may victim of security attacks. Instead use the PHP getimagesize function to check if it is really an image of supported format. http://www.php.net/getimagesize
Manuel Lemos at Quora Visit the source
Other answers
Don't take out anything! Checking for filetypes is crucial. Without it, people can upload any type of file they want - executable files, shell files, etc etc. This is a huge security risk. But, to answer your question directly, you could change the opening If statement to this: if ($_FILES["file"]["size"] < 40000000000000000) { ...} That will only check to make sure the file is below... 40 million megabytes? Am I reading that number correctly? Lol. May wanna make that smaller as well! But yeah if the upload is successful and error free, it should print out that image.
Sankho Mallik
Is that a Codeigniter snippet? Are you sure the name parameter on the input tag on the HTML side is "file"? The code you originally posted actually looks great and a lot better than what is left after you tried to implement the suggested changes.
Maarten Wolzak
Related Q & A:
- How can i upload my photos to yahoo images and watch it in my search results?Best solution by Yahoo! Answers
- How can I upload my picture into my Yahoo mail?Best solution by Yahoo! Answers
- How can I upload a video on yahoo 360?Best solution by Yahoo! Answers
- How Can i turn a black and white picture back into a colored picture?Best solution by Yahoo! Answers
- How can I upload a profile picture on yahoo?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.