PHP Upload problems

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
roshampo27
Forum Newbie
Posts: 1
Joined: Thu Nov 16, 2006 9:32 am

PHP Upload problems

Post by roshampo27 »

Burrito | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hello I have been assigned development of a file upload mechanism via http to be hosted on the company site. However, prior to this assignment I had not even written an html document. (I am a lowly help desk tech.) Fortunantly, after about a two-dozen helpful tutorials I know a little more about html perl php and cgi.  After researching various methods I decided to try using php.  First I developed a html page that meets the specs I have been given.  The html page is here: 

http://www.jonesmotorgroup.com/upload/driverupload.html

I want my php script to upload the file, allow only tiffs, limit upload size, and create a file with some info agout the upload (driver#, pro# and document type)

Currently the file is created, the pro# and driver# are in the file but the doc type is not.  Also the image is not upload.

The php script I have developed from various tutorials is

Code: Select all

<?
$fp1="../upload/upload/$pronumber";
$fh = fopen($fp1, 'a') or die("can't open file");
$stringData = "driver number is $drivernumber 1\n";
fwrite($fh, $stringData);
$stringData = "document types =  $document_type1, $document_type2, $document_type3, $document_type4, $document_type52\n";
fwrite($fh, $stringData);
fclose($fh);
$abpath = "/upload/"; 
$sizelim = "yes";
$size = "250000";
$number_of_uploads = 5;
if ($_REQUEST['submitted']){ 
$cert1 = "image/tiff";
$cert2 = "image/jpeg"; 
$log = "";
for ($i=0; $i<$number_of_uploads; $i++) {
if ($img_name[$i] == "") {
$log .= "No file selected for upload $i<br>";}
if ($img_name[$i] != "") {
if (file_exists("$abpath/$img_name[$i]")) {
$log .= "File $i already existed<br>";
} else {
if (($sizelim == "yes") && ($img_size[$i] > $size)) {
$log .= "File $i was too big<br>";
} else {
if (($img_type[$i] == $cert1) or ($img_type[$i] == $cert2)) {
@copy($img[$i], "$abpath/$img_name[$i]") or $log .= "Couldn't copy image 1 to server<br>";
if (file_exists("$abpath/$img_name[$i]")) {
$log .= "File $i was uploaded<br>";
}
} else { $log .= "File $i is not an image<br>";}}}}}
?>
<html>
<head>
<title>Image Report</title>
</head>
<body>
<p>Log:<br>
<?
echo "$log";
?>
</p>
</body>
</html>
<? 
exit;}?>
Any sugestions or ideas would really be appreciated.

Thank you


Burrito | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

have a look at is_uploaded_file(), move_uploaded_file() and become familiar with the $_FILES[] array.

that should get you started. report back with any problems you have.
Post Reply