...

View Full Version : Changing the upload destination?



garry777
01-31-2012, 12:13 AM
Hey Guys,

Ok so iv been playing around with a upload script and all is working fine and they are uploading to my /images/ folder. but i want the images to upload to a /file.html/ so they are public.
The image below is how i want them to be displayed.

http://garryashcroft.com/exam.png

At the moment i have a blank .html file, the upload script in a .php file and my styles folder.

Heres the upload script;


<?php
/*************************************************
* Uploader
*
* This was coded by james addison and is aloud to be used by anyone who leaves the copyright there
*
****************************************************/

//Windows way
$uploadLocation = "./";
//Unix, Linux way
//$uploadLocation = "\tmp";

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Uploader!</title>
<link href="style/style.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.style1 {
font-size: 10px;
font-weight: bold;
}
-->
</style>
</head>
<body>
<div id="main">
<div id="caption">UPLOAD FILE</div>
<div id="icon">&nbsp;</div>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="fileForm" id="fileForm" enctype="multipart/form-data">
File to upload:<center>
<table>
<tr><td><input name="upfile" type="file" size="36"></td></tr>
<tr><td align="center"><p><br/>
<input class="text" type="submit" name="submitBtn" value="Upload">
</p>
<p align="right" class="style1"><a href="http://hosting-town.com">Made By Hosting-Town.com - James Addison </a></p></td>
</tr>
</table></center>
</form>
<?php
if (isset($_POST['submitBtn'])){

?>
<div id="caption">RESULT</div>
<div id="icon2">&nbsp;</div>
<div id="result">
<table width="100%">
<?php

$target_path = $_SERVER['DOCUMENT_ROOT'] . '/images/' . basename( $_FILES['upfile']['name']);
if(move_uploaded_file($_FILES['upfile']['tmp_name'], $target_path)) {
echo "The file". basename( $_FILES['upfile']['name']).
"has been sucessfully uploaded.";
} else{
echo "There was an error uploading the file, please try again!";
}

?>
</table>
</div>
<?php
}
?>
<div>

Please note: You are solely responsible for any content that you may choose to upload to this site. The site owner/administrator will not accept ANY responsibility regarding illegal content that you upload. Should you not agree to these terms, please leave this page now.
</body>

Im really not sure what to do but i have a feeling it has something to do with
$target_path = $_SERVER['DOCUMENT_ROOT'] . '/images/' . basename( $_FILES['upfile']['name']);

Thanks :)

abduraooft
01-31-2012, 05:52 AM
but i want the images to upload to a /file.html/ so they are public.

You can't upload a file into a file!

You need to write some server side code in that file to list the images in it. btw, you'd need to rename your file to file.php to execute the PHP code written in it.

garry777
01-31-2012, 06:11 AM
You can't upload a file into a file!

You need to write some server side code in that file to list the images in it. btw, you'd need to rename your file to file.php to execute the PHP code written in it.


mmm ok well is there some server side code on the net that i could copy? Iv never dealt with that before. Or does anyone on here have one?

Cheers

abduraooft
01-31-2012, 06:45 AM
Or does anyone on here have one?
You could use the glob() (http://php.net/glob) function to grab all images from a directory and then use a loop (say foreach() (http://php.net/foreach)) to display them using <img> tags.

garry777
01-31-2012, 06:55 AM
You could use the glob() (http://php.net/glob) function to grab all images from a directory and then use a loop (say foreach() (http://php.net/foreach)) to display them using <img> tags.

How would you place them in the image tags? Im sorry im only a newby :)

could you give me an example please?




Cheers

abduraooft
01-31-2012, 07:04 AM
Try something like

<?php
$images=glob($_SERVER['DOCUMENT_ROOT'] . '/images/*.{jpg,png,gif}',GLOB_BRACE);
foreach($images as $image){
$size=getimagesize($image);
echo '<img src="images/'.basename($image).'" width="'.$size[0].'" height="'.$size[1].'" >';
}

?>

garry777
01-31-2012, 07:15 AM
Try something like

<?php
$images=glob($_SERVER['DOCUMENT_ROOT'] . '/images/*.{jpg,png,gif}',GLOB_BRACE);
foreach($images as $image){
$size=getimagesize($image);
echo '<img src="images/'.basename($image).'" width="'.$size[0].'" height="'.$size[1].'" >';
}

?>


Awesome, thank you so so much :)

Now how could i make a default size? Also do you know how i would position them like this image?

http://garryashcroft.com/exam.png

abduraooft
01-31-2012, 07:22 AM
Now how could i make a default size?
In order to keep the proportion, you'd need to resize the image at the time of upload. Otherwise, you may set a fixed width and height values while echoing the images.


Also do you know how i would position them like this image?
Echo a line break (<br>) after every two images inside the loop.

garry777
01-31-2012, 08:17 AM
In order to keep the proportion, you'd need to resize the image at the time of upload. Otherwise, you may set a fixed width and height values while echoing the images.


Echo a line break (<br>) after every two images inside the loop.

Could you show me what you mean?

abduraooft
01-31-2012, 10:59 AM
<?php
$images=glob($_SERVER['DOCUMENT_ROOT'] . '/images/*.{jpg,png,gif}',GLOB_BRACE);
$i=0;
foreach($images as $image){
echo '<img src="images/'.basename($image).'" width="230" height="100" >';
$i++;
if($i%2==0) echo '<br>';
}

?>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum