Connecting Tech Pros Worldwide Forums | Help | Site Map

q. Script to allow users to upload photos

Willoughby Bridge
Guest
 
Posts: n/a
#1: Jul 17 '05
I am trying to create a php script to allows users to upload photos:

The first file looks like this:



<html>

<head>

<title>Upload Photo</title>

</head>

<body>

<BODY LINK="#0000ff" VLINK="#800080" BACKGROUND="./wall.jpg">

<br>

<Font Size =4/><B/>Upload Photo For Teacher Card: <br><br><br></Font Size
=4>



<form action="UploadPhoto2.php" enctype="multipart/form-data" method="POST">

<input type="hidden" name="MAX_FILE_SIZE" value="51200">

File to Upload: <input type="file" name="fileupload"><br><br>

<input type="submit" value="Upload!">

</form>

</body>

</html>



It calls the second file that looks like this:



<html>

<head>

<title>Listing 9.14 A file upload script</title>

</head>

<body>

<h1>File had been uploaded successfully</h1>



<br>

<br>



</FONT><P><P ALIGN="LEFT"></FONT>&nbsp;&nbsp;&nbsp;&nbsp;<A
HREF="http://www.teachercards.org"><FONT SIZE=3>Return Home</FONT></A></P>



<?php

$file_dir = "/uploads"; set up this directory wanting photos would be
uploaded here and it is not working.



foreach($_FILES as $file_name => $file_array) {

print "path: ".$file_array['tmp_name']."<br>\n";

print "name: ".$file_array['name']."<br>\n";

print "type: ".$file_array['type']."<br>\n";

print "size: ".$file_array['size']."<br>\n";



if (is_uploaded_file($file_array['tmp_name'])) {

move_uploaded_file($file_array['tmp_name'],
"$file_dir/$file_array[name]") or die ("Couldn't copy");

print "file was moved!<br><br>";

}

}

?>

</html>



I am pretty sure the problem is in the second file and the code just needs
to be made more specific to my web site. But not sure how to do it and
would appreciate some help.



TIA



David



cyberhorse
Guest
 
Posts: n/a
#2: Jul 17 '05

re: q. Script to allow users to upload photos


look at the gallery script on sourceforge
(http://sourceforge.net/projects/sphp) for some ideas and hints ...
it's a bit more developed, but it still sticks to basics (no db)

Closed Thread


Similar PHP bytes