Jump to content

i need help with easy php


perezf

Recommended Posts

I just finished making this script from scratch, i am a beginner in php and was wondering how i can  set my file uploader to only upload images and also not to upload the image if the file already exist?

[quote]<div align="center"><h1>Picture Easy Uploader</h1><?php
if(isset($_POST['Submit'])){
if ($_FILES[image] != '') {
@copy($_FILES[image][tmp_name],
"uploads/".$_FILES[image][name])
or die("Couldn't copy the file.");
echo "The file upload was a success, click on the link to see it. <a href=\"uploads/".$_FILES[image][name]."\">Click Here</a><br />";
echo "The Myspace code is as follows<br /><b>&lt;img src=\"http://2fr3sh.com/scripts/uploads/".$_FILES[image][name]."\" /&gt;</b> <br />";
echo "A preview is below<br /><a href=\"uploads/".$_FILES[image][name]."\"><img src=\"http://2fr3sh.com/scripts/uploads/".$_FILES[image][name]."\" width=\"150\" /></a>";
} else {
die("No Input File Specified");
}} else{
?>

<form action="" method="post" enctype="multipart/form-data" name="form1">
  <input type="file" name="image">
  <br>
  <input type="submit" name="Submit" value="Upload Your File">
</form>
<?php }
$dir_name = "uploads/";
$dir = opendir($dir_name);

$file_list = "<ol>";
while ($file_name = readdir($dir)){

if (($file_name != ".") && ($file_name != "..")) {
$file_list .= "<li><a href=\"uploads/".$file_name."\">".$file_name;
echo "</a>";
}
}

$file_list .= "</ol>";
echo "<div align=\"left\">";
echo "The files currently uploaded are as follows:<br />".$file_list;
echo "</div>";
?>
</div> [/quote] :)
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.