Adding upload funtion

danbnpp

New Member
Hello

I have a question about adding upload options for my site, I run a site for a local band and I want to give people the ability to upload pictures and videos from shows. Where can I go to get the info on doing this?

Thanks
 

danbnpp

New Member
Can you be more spasific? I get a billion things when I look it up, in the mean time if any one else has something to check out I'll test out the one I found from the w3 site.
 

chrishirst

Well-Known Member
Staff member
Can you be more spasific? I get a billion things when I look it up, in the mean time if any one else has something to check out I'll test out the one I found from the w3 site.
Did you try narrowing the search query?

Like Google, I cannot be more specific until you are less vague in your question. I could point you to some code to upload images that was written in vBScript for an ASP powered site backend. Which would be pretty useless if your server only ran Perl as CGI or was coded in ColdFusion.
 

danbnpp

New Member
What I'm looking for is a way to upload pics and videos to my site http://www.nimbusplanetproductions.com
I found this
Code:
<html>
 <body>
 
<form action="uploads.php" method="post"
 enctype="multipart/form-data">
 <label for="file">Filename:</label>
 <input type="file" name="file" id="file" /> 
<br />
 <input type="submit" name="submit" value="Submit" />
 </form>
 
</body>
 </html>
and the php scipt
Code:
<?php
 $allowedExts = array("jpg", "jpeg", "gif", "png");
 $extension = end(explode(".", $_FILES["file"]["name"]));
 if ((($_FILES["file"]["type"] == "image/gif")
 || ($_FILES["file"]["type"] == "image/jpeg")
 || ($_FILES["file"]["type"] == "image/pjpeg"))
 && ($_FILES["file"]["size"] < 20000)
 && in_array($extension, $allowedExts))
   {
   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("uploads/" . $_FILES["file"]["name"]))
       {
       echo $_FILES["file"]["name"] . " already exists. ";
       }
     else
       {
       move_uploaded_file($_FILES["file"]["tmp_name"],
       "upload/" . $_FILES["file"]["name"]);
       echo "Stored in: " . "uploads/" . $_FILES["file"]["name"];
       }
     }
   }
 else
   {
   echo "Invalid file";
   }
 ?>
This is kind of what I'm looking for but under testing it says invalid file, the folder was set at 777 and everything checks out with the links but nothing is working. My site is on godaddy the page I put the code in is http://www.nimbusplanetproductions.com/photos/
I'd like to figure this out cause I need it for photos and videos from fans.
 

chrishirst

Well-Known Member
Staff member
Well at least we have found out that it was a php script you needed.

So, at what point in the process does it error out and what type of file are you trying to upload?
 

danbnpp

New Member
Ok how I tested it out was by uploading all three files (including the index which had the link to the htmal document) into the proper location. I went to my site and to the photos page and clicked the link, the page opened up and I selected a jpg image to up load and clicked submit or upload. I get the error invalid file 20 seconds later. As you can see the code says to place the files in the /uploads folder. I'm learning as I go, this is the second one I've looked at for my site and I still have work to do on the design and stuff.I don't know if it's the file size limit or some other restriction, once I get it to work I can figure out how to mod it to upload videos.Any one have any ideas what could be wrong? I'll try changing the size limit and see, could it be the url of the upload folder?
 

chrishirst

Well-Known Member
Staff member
Do NOT leave the "/uploads" with 777 permissions, especially if the folder is going to be exposed to the whole world in an image path.

The upload is succeeding, but the MIME type or extension check is failing. Check the extension of the file you tested with it MUST be all lowercase to match with one of the array values.
 

danbnpp

New Member
Ok so what setting should it be at in the permissions? I'll look at your link and see if it helps me. From relpy#12 makes me wonder how to mod the script for all magor image files. Sorry but I'm kinda new to this and having some html experience I'm learning as I go along, what can I say I like to see it work instead of reading about it.

Ok so I just checked the link posted in reply #13 and took me to scripts so what do I add to the script I made to acomidat all major image formats? How hard would it be to mod it for videos?
 
Last edited:

Roddy

New Member
Add the file type to this...

$allow_types=array("jpg","gif","png","zip","txt","doc","mov");

Note that I added .mov

Increase the max size per file...

$max_file_size="5000";

...and the max size for combined files...

$max_combined_size="10000";

... to something more reasonable for movies
 

danbnpp

New Member
Well I did some modding to the php script and I got this, Upload: 373678_462149883815446_111042438_n.jpg
Type: image/pjpeg
Size: 18.6806640625 Kb
Temp file: /tmp/phpR5s7ey
Stored in: uploads/373678_462149883815446_111042438_n.jpg

I checked the folder in filezilla and the image isn't there, what did I do wrong and what file permission settings to I need for the folder?
 

chrishirst

Well-Known Member
Staff member
Add the file type to this...

$allow_types=array("jpg","gif","png","zip","txt","doc","mov");

Note that I added .mov

Increase the max size per file...

$max_file_size="5000";

...and the max size for combined files...

$max_combined_size="10000";

... to something more reasonable for movies

For the current script you would also have to add the appropriate MIME type(s)

Code:
video/quicktime
would be the minimum
with
Code:
video/quicktime, video/x-quicktime, image/mov, audio/aiff, audio/x-midi, audio/x-wav, video/avi

covering all bases.
 
Last edited:

danbnpp

New Member
Ok so why isn't the pics showing up in uploads folder? in response 17 I got that messeage after O modded the php script to this
Code:
<?php
 $allowedExts = array("jpg", "jpeg", "JPG", "gif", "png", "bmp");
 $extension = end(explode(".", $_FILES["file"]["name"]));
 if ((($_FILES["file"]["type"] == "image/gif")
 || ($_FILES["file"]["type"] == "image/jpeg")
 || ($_FILES["file"]["type"] == "image/JPG")
 || ($_FILES["file"]["type"] == "image/bmp")
 || ($_FILES["file"]["type"] == "image/pjpeg"))
 && ($_FILES["file"]["size"] < 250000)
 && in_array($extension, $allowedExts))
   {
   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("uploads/" . $_FILES["file"]["name"]))
       {
       echo $_FILES["file"]["name"] . " already exists. ";
       }
     else
       {
       move_uploaded_file($_FILES["file"]["tmp_name"],
       "uploads/" . $_FILES["file"]["name"]);
       echo "Stored in: " . "uploads/" . $_FILES["file"]["name"];
       }
     }
   }
 else
   {
   echo "Invalid file";
   }
 ?>
So why isn't it showing up? And what should the permission on the folder be set at?
 
Top