How to: 'browse' for client file then 'upload' to my server

Dreamweaver & Flash (ahh ahhh) plus Web related Tutorials & Resources, HTML, CSS, PHP, Flash or whatever.
Post Reply
morphim
Site Admin
Posts: 609
Joined: January 5th, 2006, 2:21 pm
Location: Next Rock after the one Cow's at

How to: 'browse' for client file then 'upload' to my server

Post by morphim » April 28th, 2008, 10:21 am

Hello. I've mentioned this to Cow but he was little help without the offer of money / sexual favours, sooo ....

I need to set up a simple user page for 'browse your computer for file' then 'upload' to my server for this poster printing site I'm working on.
I need this functionality set up first really.

I need to be able to specify file types and max size.
I have php on my server (not sure what else?)
Is there an easy(ish) way of doing this. Any freeware scripts? Anything at all??

Any help / advice / input greatly received.

Thanks in advance

M.
It's always a sunny day above the clouds : )

Simon
A Pig in Space
A Pig in Space
Posts: 484
Joined: January 7th, 2006, 10:55 am
Location: Devon
Contact:

Post by Simon » April 28th, 2008, 7:04 pm

i did this to upload images, its a simple one, trying to search for my complicated one, that also resizes it.

But it can be amended for different file types I beleive.

Code: Select all

<body> 
<?php 

// Check if the form has been submitted. 
if (isset($_POST['submitted'])) { 

   // Check for an uploaded file. 
   if (isset($_FILES['upload'])) { 
       
      // Validate the type. Should be jpeg, jpg, or gif. 
      $allowed = array ('image/gif', 'image/jpeg', 'image/jpg', 'image/pjpeg'); 
      if (in_array($_FILES['upload']['type'], $allowed)) { 
       
         // Move the file over. 
         if (move_uploaded_file($_FILES['upload']['tmp_name'], "uploads/{$_FILES['upload']['name']}") )  { 
		 		  // this bits simply displays the image you just uploaded and the image name if upload is ok.
		  echo '<p>File name loaded: ' . $_FILES['upload']['name'] .'</p>';
		  echo '<p>File name loaded: ' . $_FILES['upload2']['name'] .'</p>';
            echo '<p>The file has been uploaded!</p>'; 
			
			/////////////////////  add to db info goes here.
			//  if you want to add the image and information to the database simply use the variable below
			// $imageName = $_FILES['upload']['name']; 
			//  that way add the variable  $imageName t the insert db code for the image.
			
         } else { // Couldn't move the file over. 
          
            echo '<p><font color="red">The file could not be uploaded because: </b>'; 
       
            // Print a message based upon the error. 
            switch ($_FILES['upload']['error']) { 
               case 1: 
                  print 'The file exceeds the upload_max_filesize setting in php.ini.'; 
                  break; 
               case 2: 
                  print 'The file exceeds the MAX_FILE_SIZE setting in the HTML form.'; 
                  break; 
               case 3: 
                  print 'The file was only partially uploaded.'; 
                  break; 
               case 4: 
                  print 'No file was uploaded.'; 
                  break; 
               case 6: 
                  print 'No temporary folder was available.'; 
                  break; 
               default: 
                  print 'A system error occurred.'; 
                  break; 
            } // End of switch. 
             
            print '</b></font></p>'; 

         } // End of move... IF. 
          
      } else { // Invalid type. 
         echo '<p><font color="red">Please upload a JPEG or GIF image.</font></p>'; 
         unlink ($_FILES['upload']['tmp_name']); // Delete the file. 
      } 

   } else { // No file uploaded. 
      echo '<p><font color="red">Please upload a JPEG or GIF image smaller than 512KB.</font></p>'; 
   } 
          
} // End of the submitted conditional. 
?> 
    
<form enctype="multipart/form-data" action="upload_image.php" method="post"> 

   <input type="hidden" name="MAX_FILE_SIZE" value="524288"> 
   <fieldset><legend>Select a JPEG or GIF image to be uploaded:</legend> 
    
   <p><b>File:</b> <input type="file" name="upload" /></p> 
   <p><b>File:</b> <input type="file" name="upload2" /></p> 
   </fieldset> 
   <div align="center"><input type="submit" name="submit" value="Submit" /></div> 
   <input type="hidden" name="submitted" value="TRUE" /> 
</form> 
</body> 
there is a god, and i am him

Simon
A Pig in Space
A Pig in Space
Posts: 484
Joined: January 7th, 2006, 10:55 am
Location: Devon
Contact:

Post by Simon » April 28th, 2008, 7:07 pm

heres a tut: not tried it but here goes:TUT HERE
there is a god, and i am him

morphim
Site Admin
Posts: 609
Joined: January 5th, 2006, 2:21 pm
Location: Next Rock after the one Cow's at

Post by morphim » April 29th, 2008, 7:48 am

Thanks, Simon. I'll give it a go.

I just need something quick and easy for now, just to get things up and running as I don't want files being sent to me via e-mail.
I need to make it easy for users to upload the files so I can then download at my leisure.
It als means I can use my NTL bandwidth rather than waste it with my descent, paid hosting

Cheers :D
It's always a sunny day above the clouds : )

cow
A Pig in Space
A Pig in Space
Posts: 309
Joined: January 6th, 2006, 10:44 am
Location: 4th rock from morphims house
Contact:

Post by cow » April 30th, 2008, 8:12 am

Regarding bandwidth, I'd expect your host to consider ftp bandwidth as important as mail bandwidth, with the kb transferred all counting?

How are you going to stop people from just uploading masses of stuff. Meaning random third-parties rather than trusted folk?

Are you going to have some kind of registration system, and if so is it automated or manual, database-driven or secure?

I always ask more questions than I have time to answer, but these issues are important if you're running this as a part of your business, and this is only the start.

(Not trying to be negative, just realistic)
<? include['cows go moo'] ?>

morphim
Site Admin
Posts: 609
Joined: January 5th, 2006, 2:21 pm
Location: Next Rock after the one Cow's at

Post by morphim » April 30th, 2008, 11:11 am

OK. I've installed both (yours and tut example) to my web space.
Any idea why it might hang?
It seems rather tempremental(?). Hangs more when the file type or size is wrong but rarely shows an error. It just shows 'loading' all the time in the tab.

The only things I've altered are the file types (left all the jpeg variations but added .pdf) and the max file size (set to 35mb = 3600000

They are here >>

http://citizenart.com/upload/upload.php (tut example)

http://citizenart.com/upload/uploadA.php (your version)

Might it be an access / communication issue on the server?
It's definitley doing something because web browsing / e-mail is really slow whilst it's messing around.
It's always a sunny day above the clouds : )

cow
A Pig in Space
A Pig in Space
Posts: 309
Joined: January 6th, 2006, 10:44 am
Location: 4th rock from morphims house
Contact:

Post by cow » April 30th, 2008, 4:30 pm

morphim wrote:The only things I've altered are the ....... max file size set to 35mb = 3600000
:shock: Fucking Hell !

Get ready to purchase a dedicated server :wink:

Tip: you need to access your php.ini file on your server to see what the max_upload size is set to. Also, you really need to know how much memory you're allocated. That really is a huge limit to co-exist with a basic script such as this.
<? include['cows go moo'] ?>

cow
A Pig in Space
A Pig in Space
Posts: 309
Joined: January 6th, 2006, 10:44 am
Location: 4th rock from morphims house
Contact:

Post by cow » April 30th, 2008, 4:33 pm

ps. It works for me with small files, as you'll see.
<? include['cows go moo'] ?>

Simon
A Pig in Space
A Pig in Space
Posts: 484
Joined: January 7th, 2006, 10:55 am
Location: Devon
Contact:

Post by Simon » April 30th, 2008, 10:22 pm

the first one works but the second one I get your 404 error page seems to not find the http://citizenart.com/upload/upload_image.php page??
there is a god, and i am him

morphim
Site Admin
Posts: 609
Joined: January 5th, 2006, 2:21 pm
Location: Next Rock after the one Cow's at

Post by morphim » May 1st, 2008, 11:33 am

Thanks for the replies :D

So, Cow, how can I get files of this size from these people? I need them to upload them somewhere so they can link to them and let me download.
Are there better ways?

I have altered my php.ini file already.
The thing is, these files will only be uploaded so i can download them. They don't need to be stored on the server.

Are there any free upload sites that will take files of this size.
All need to be easy for them and me :D
It's always a sunny day above the clouds : )

morphim
Site Admin
Posts: 609
Joined: January 5th, 2006, 2:21 pm
Location: Next Rock after the one Cow's at

Post by morphim » May 1st, 2008, 11:37 am

Thanks for the image uploads too :roll: :lol:

Car looks nice and shiney.
Seahorses are amazing ... how long did they take you :wink:

Finally, this explains a lot about the person you are today. It's spelt 'can't
It's always a sunny day above the clouds : )

cow
A Pig in Space
A Pig in Space
Posts: 309
Joined: January 6th, 2006, 10:44 am
Location: 4th rock from morphims house
Contact:

Post by cow » May 1st, 2008, 3:25 pm

morphim wrote:I have altered my php.ini file already.
The thing is, these files will only be uploaded so i can download them. They don't need to be stored on the server.
This'll be brief because I've been to the pub and am reasonably drunk. The files will be stored on the server, if only briefly. You could look for some 'free' space, I'm not sure whta's out there. I'm off to make cheese on toast.

M
<? include['cows go moo'] ?>

morphim
Site Admin
Posts: 609
Joined: January 5th, 2006, 2:21 pm
Location: Next Rock after the one Cow's at

Post by morphim » May 1st, 2008, 3:26 pm

OK, don't worry too much about this now. I have been directed to a couple of free upload site which look like they'll do the trick with much less input from me ... which is always a good thing :D
It's always a sunny day above the clouds : )

Post Reply