PDA

Click to See Complete Forum and Search --> : [RESOLVED] image upload form


Justa Lol
Nov 24th, 2009, 08:00 AM
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?

SambaNeko
Nov 24th, 2009, 11:13 AM
On your upload.processor.php page, the file name of the uploaded file can be retrieved with:

basename($uploadFilename);


You could add this to your redirect...

header('Location: ' . $uploadSuccess.'?img='.basename($uploadFilename));

...and then translate it to a full URL on the success page:

<?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>

Justa Lol
Nov 24th, 2009, 12:00 PM
as i said, i'm completely blank on php, where do you want me to put the 2 first codes you give me?

kows
Nov 24th, 2009, 12:13 PM
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.

SambaNeko
Nov 24th, 2009, 01:09 PM
Like kows said.

The second bit of code should replace this line in your upload.processor.php page:

header('Location: ' . $uploadSuccess);


The third code block can entirely replace the contents of upload.success.php.

Justa Lol
Nov 24th, 2009, 01:23 PM
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...