...

View Full Version : Uploading Pics



ZunskiGraphics
01-12-2006, 05:21 PM
I used this tutorilal to help me create an upload button so a user could upload a picture. problem is, I cant tell if its working or not. the example for the tutorial is here:
http://www.htmlgoodies.com/beyond/php/article.php/3472551

the example I did is on the web here:
www.ten14.net/ten14home.swf

(click the "come work with us" button in the top right.)

can anyone tell me what is wrong? or right?

Thanks
Z

jabbic
01-12-2006, 07:04 PM
Sorry didn't mean to post.

Element
01-12-2006, 11:27 PM
I made this for multiple uploading, it should help. It was in the snippets section but apparently a mod doesn't think uploading multiple images (something you can't just do with a regular function) wasn't usefull.




<?php

$file_path = "p_images/";
if(!(is_dir($file_path))) {
if(!(mkdir($file_path, 0777))) {
die("The directory <b>".$file_path."</b> doesn't exist and could not be created!");
}
}

if(isset($_POST['submit'])) {
echo "<p>";
while(list($key,$val) = each($_FILES['imagefiles']['name'])) {
if(isset($val)) {

$filename = $val;
$file = $_FILES['imagefiles']['tmp_name'][$key];

if (preg_match("/.(jpg|jpeg|png|gif)/i", $filename)) {
$valid = true;
} else {
$valid = false;
}

if ($valid) {

$ext = substr($filename, strpos($filename, ".")+1, strlen($filename));
$new_filename = substr(md5(microtime()), 0, 8).".".$ext;

if(@copy($file, $file_path . $new_filename)) {
if(@chmod($file_path . $new_filename, 0777)) {
echo "<b>Image " . $key . "</b>: <a href=\"http://" . $_SERVER['HTTP_HOST'] . "/" . $file_path . $new_filename . "\" target=\"_blank\">http://" . $_SERVER['HTTP_HOST'] . "/" . $file_path . $new_filename . "</a><br />\n";
} else {
echo "<b>Image " . $key . "</b>: <a href=\"http://" . $_SERVER['HTTP_HOST'] . "/" . $file_path . $new_filename . "\" target=\"_blank\">http://" . $_SERVER['HTTP_HOST'] . "/" . $file_path . $new_filename . "</a> FAILED TO CHMOD!<br />\n";
}
}
}

}

echo "</p>";

}

} else {

echo "<form method=\"post\" action=\"" . $_SERVER['REQUEST_URI'] . "\" enctype=\"multipart/form-data\">\n";
for($i=1; $i<=6; $i++) {
$format = $i % 3 ? "" : "<br />";
echo "<input type=\"file\" name=\"imagefiles[]\">" . $format . "\n";
}
echo "<input type=\"submit\" name=\"submit\" value=\"Upload Images\">";
echo "</form>";

}

?>

ZunskiGraphics
01-13-2006, 03:00 PM
$file_path = "p_images/";



I assume that in the quotations is where I would put the name of the file in the server that is holding all the pics?

THANKS I'm going to try this out...

Z

ZunskiGraphics
01-13-2006, 03:14 PM
Let me show you what I have....

I have a button, that when clicked takes you here

http://www.ten14.net/step1.html

here is my code for that page.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Work For Ten14 | You must complete each step!</title>
<style type="text/css">
<!--
body {
background-image: url(ten14bg.png);
}
.style2 {color: #FFFFFF; font-family: Verdana, Arial, Helvetica, sans-serif; }
.style3 {
font-size: 24px;
font-weight: bold;
}
.style5 {font-size: 24px}
.style6 {color: #FFFFFF}
.style7 {
color: #FFFFFF;
font-style: italic;
}
.style8 {color: #600000}
-->
</style>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->
</script>
</head>

<body>
<div id="Layer1" style="position:absolute; left:341px; top:115px; width:463px; height:229px; z-index:1">
<p class="style2"><span class="style3">STEP 1</span><span class="style5">:</span></p>
<p class="style2">Please upload a photo of yourself. </p>

<form action="getfile.php" method="post"><br></br>
<span class="style6">Upload File:</span>
<input type="file" name="uploadFile" />
<input type="submit" value="Upload File"/>
<input type="hidden" name="MAX_FILE_SIZE" value="25000" />
</form>

<p class="style7"> (you must complete this step to full out application)</p>
</div>
</body>
</html>



Now it's supposed to call this php code:


<html>
<head>
<title>Process Uploaded File</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><style type="text/css">
<!--
body,td,th {
color: #FFFFFF;
}
body {
background-image: url(ten14bg.png);
}
-->
</style></head>
<body>


<?php

if ( move_uploaded_file ($_FILES['uploadFile'] ['tmp_name'],
"../uploads/{$_FILES['uploadFile'] ['name']}") )
{ print '<p> The file has been successfully uploaded </p>';
}
else
{
switch ($_FILES['uploadFile'] ['error'])
{ case 1:
print '<p> The file is bigger than this PHP installation allows</p>';
break;
case 2:
print '<p> The file is bigger than this form allows</p>';
break;
case 3:
print '<p> Only part of the file was uploaded</p>';
break;
case 4:
print '<p> No file was uploaded</p>';
break;
}
}

?>


</body>
</html>


I tried to substitute your php file for mine, but yours has 6 uploading buttons, and when I tried to submit a file, it still just went to a blank browser screen. I chenges my file directory to p_images. (I left my previous one as well uploads on the server too) I'm very confused....please help...thanks!

z



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum