Results 1 to 6 of 6

Thread: [RESOLVED] image upload form

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    1,023

    Resolved [RESOLVED] image upload form

    i'm completely blank on php, what i need is the uploader to return a link to the image that has been uploaded. i attached my php upload form..

    could someone tell me how to do this?


    well if not return the link, then just the filename that was uploaded, not afterwards?
    Last edited by Justa Lol; Nov 25th, 2009 at 10:29 AM.

  2. #2
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,516

    Re: image upload form

    On your upload.processor.php page, the file name of the uploaded file can be retrieved with:
    Code:
    basename($uploadFilename);
    You could add this to your redirect...
    Code:
    header('Location: ' . $uploadSuccess.'?img='.basename($uploadFilename));
    ...and then translate it to a full URL on the success page:
    Code:
    <?php
    
    // filename: upload.success.php
    
    // make a note of the current working directory, relative to root.
    $directory_self = str_replace(basename($_SERVER['PHP_SELF']), '', $_SERVER['PHP_SELF']);
    
    // make a note of the directory that will recieve the uploaded files
    $uploadsDirectory = 'http://'.$_SERVER['HTTP_HOST'] . $directory_self . 'uploaded_files/';
    
    ?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
    
    <html lang="en">
    	<head>
    		<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
    		
    		<link rel="stylesheet" type="text/css" href="stylesheet.css">
    		
    		<title>Successful upload</title>
    	
    	</head>
    	
    	<body>
    	
    		<div id="Upload">
    			<h1>File upload</h1>
    			<p>Congratulations! Your file upload was successful</p>
    			<p><?php echo $uploadsDirectory.$_GET['img'];?></p>
    		</div>
    	
    	</body>
    
    </html>

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    1,023

    Re: image upload form

    as i said, i'm completely blank on php, where do you want me to put the 2 first codes you give me?

  4. #4
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: image upload form

    the first piece of code is just an example of usage, and the second piece would be how to implement it.

    the second piece of code should be added to whatever line that is calling the "header()" function -- you would be adding the last bit to it. you could probably find this line easiest by "Find"-ing the string header( and then adding onto it. be sure you add your text within the parenthesis.

  5. #5
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,516

    Re: image upload form

    Like kows said.

    The second bit of code should replace this line in your upload.processor.php page:
    Code:
    header('Location: ' . $uploadSuccess);
    The third code block can entirely replace the contents of upload.success.php.

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2008
    Posts
    1,023

    Re: image upload form

    sorry i figured this out, just couldn't get on the forum to mark as resolved because it lagged a bit for me so i just got on working with my website...

    edit: thanks to both of you btw...
    Last edited by Justa Lol; Nov 24th, 2009 at 02:44 PM.

Posting Permissions

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



Click Here to Expand Forum to Full Width