Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: Java Upload

  1. #1
    New to the CF scene
    Join Date
    Jun 2012
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Unhappy Java Upload

    Hey guys, not sure if this is the right section or not (sorry)

    Anyway, im recently realised that instead of making an upload.php page which your browser needs to redirect you to for the file to upload, you can just use a jquery upload, which bascially doesn't have to change page for the upload to happen

    I have used this script http://www.9lessons.info/2011/08/aja...efreshing.html

    Except I have taken out the bits where it has to connect to the database for a login ect. It still is not working though so I was wondering please if anyone is experienced with jquery if they could please help me solve a few of the issues im having atm

    Thanks
    Last edited by remmaz; 06-13-2012 at 11:55 PM.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Despite the similar sounding names, Java is not the same as Javascript.
    Moving from Java forum to Javascript forum.

  • #3
    Senior Coder
    Join Date
    Jan 2005
    Location
    Memphis, TN
    Posts
    1,785
    Thanks
    8
    Thanked 131 Times in 129 Posts
    Try a simpler tutorial. No database to mess with just in case that's where the issue you're having is.

    http://net.tutsplus.com/tutorials/ja...les-with-ajax/
    Stop making things so hard on yourself.
    i is tugbucket :: help raise tugburg :: Whitehaven Kiwanis

  • Users who have thanked harbingerOTV for this post:

    remmaz (06-14-2012)

  • #4
    New to the CF scene
    Join Date
    Jun 2012
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts
    @harbinger

    Thanks a heap! That tut was awesome and actually worked!

    There was only one problem though, after you have chosen a file and it uploads it just shows what you uploaded, how could I make it so it will give you the download link for the file?

    EDIT: Also how do I make it so it allows every file type? So it's not just an image uploader but you can upload everything?


    Thanks

  • #5
    Senior Coder
    Join Date
    Jan 2005
    Location
    Memphis, TN
    Posts
    1,785
    Thanks
    8
    Thanked 131 Times in 129 Posts
    okay, go back to your original tutorial: http://www.9lessons.info/2011/08/aja...efreshing.html

    From index.php, remove:
    Code:
    <?php
    include('db.php');
    session_start();
    $session_id='1'; //$session id
    ?>
    make the ajaximage.php this:
    Code:
    <?php
    $path = "uploads/"; // set the uploads folder location
    
    	$valid_formats = array("jpg", "png", "gif", "bmp", "rtf"); // notice I added rtf as an example
    	if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST")
    		{
    			$name = $_FILES['photoimg']['name'];
    			$size = $_FILES['photoimg']['size'];
    			
    			if(strlen($name))
    				{
    					list($txt, $ext) = explode(".", $name);
    					if(in_array($ext,$valid_formats))
    					{
    					if($size<(1024*1024))
    						{
    							/* $actual_image_name = time().substr(str_replace(" ", "_", $txt), 5).".".$ext; */ // this line renames your files to prevent over writing
    							$actual_image_name = $txt.".".$ext;
    							$tmp = $_FILES['photoimg']['tmp_name'];
    							if(move_uploaded_file($tmp, $path.$actual_image_name))
    								{
    								/* mysql_query("UPDATE users SET profile_image='$actual_image_name' WHERE uid='$session_id'"); */ // this was the connection to the database
    									
    									/* echo "<img src='uploads/".$actual_image_name."'  class='preview'>"; */ // this made the images after upload
    									/* the below creates a list of all uploaded files on success */
    									$dir = opendir($path); // open the uploads directory
    									echo '<ul>'; // create the ul
    									while ($read = readdir($dir)){ // if the folder is readable
    										if ($read!='.' && $read!='..'){ // check to make sure your not reading directories
    											echo '<li><a href="uploads/'.$read.'">'.$read.'</a></li>'."\n"; // list out all the files
    										}
    
    									}
    									echo '</ul>'; // close the ul
    									closedir($dir); // close the opendir()
    								}
    							else
    								echo "failed";
    						}
    						else
    						echo "Image file size max 1 MB";					
    						}
    						else
    						echo "Invalid file format..";	
    				}
    				
    			else
    				echo "Please select image..!";
    				
    			exit;
    		}
    ?>
    read the comments I added and hopefully it should be pretty clear.
    Stop making things so hard on yourself.
    i is tugbucket :: help raise tugburg :: Whitehaven Kiwanis


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •