1,105,585 Community Members

Upload help ????

Member Avatar
kzip
Newbie Poster
4 posts since Jan 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

-upload.php-

<table width="500" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form action="rename.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td><strong>Single File Upload </strong></td>
</tr>
<tr>
<td>Select file 
<input name="ufile" type="file" id="ufile" size="50" /></td>
</tr>
<tr>
<td align="center"><input type="submit" name="Submit" value="Upload" /></td>
</tr>
</table>
</td>
</form>
</tr>
</table>

-rename.php-

<?php
// Your file name you are uploading 
$file_name = $HTTP_POST_FILES['ufile']['name'];
// random 5 digit to add to our file name 
// some people use date and time in stead of random digit 
$random_digit=rand(00000,99999);
// spliter
$desh  = ".";
//combine random digit to you file name to create new file name
//use dot (.) to combile these two variables
$new_file_name=$random_digit.$desh.$file_name;
//set where you want to store files
//in this example we keep file in folder upload 
//$new_file_name = new upload file name
//for example upload file name cartoon.gif . $path will be upload/cartoon.gif
$path= "upload/".$new_file_name;
if($ufile !=none)
{
if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path))
{
echo "Successful<BR/>";
//$new_file_name = new file name
//$HTTP_POST_FILES['ufile']['size'] = file size
//$HTTP_POST_FILES['ufile']['type'] = type of file
echo "File Name :".$new_file_name."<BR/>"; 
echo "File Size :".$HTTP_POST_FILES['ufile']['size']."<BR/>"; 
echo "File Type :".$HTTP_POST_FILES['ufile']['type']."<BR/>"; 
echo "<img src=\"$path\" width=\"150\" height=\"150\">";
}
else
{
echo "Error";
}
}
?>

the script needs to look if the files are photos it need to allow (jpg,png,bmp,gif) and block anything else
can any wone help me ? tnx kevin

Member Avatar
Stefano Mtangoo
Senior Poster
3,713 posts since Jun 2007
Reputation Points: 441 [?]
Q&As Helped to Solve: 394 [?]
Skill Endorsements: 2 [?]
 
0
 
Member Avatar
mathieu89
Light Poster
37 posts since Nov 2010
Reputation Points: 14 [?]
Q&As Helped to Solve: 4 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi,

Have you tried putting an if statement at the start to only allow images?
Like this...

if ($HTTP_POST_FILES['type']=="jpg"){ all your code} 
else { echo "only jpg allow";}

or it might be better to do it this way

if ($HTTP_POST_FILES['type']!="jpg"){ echo "jpg only allowed";} 
else { all you code}
Member Avatar
mathieu89
Light Poster
37 posts since Nov 2010
Reputation Points: 14 [?]
Q&As Helped to Solve: 4 [?]
Skill Endorsements: 0 [?]
 
0
 

Actually the url that evstevemd posted is much better:) use that!

Member Avatar
kzip
Newbie Poster
4 posts since Jan 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi,

Have you tried putting an if statement at the start to only allow images?
Like this...

if ($HTTP_POST_FILES['type']=="jpg"){ all your code} 
else { echo "only jpg allow";}

or it might be better to do it this way

if ($HTTP_POST_FILES['type']!="jpg"){ echo "jpg only allowed";} 
else { all you code}

so i got this but its not working

<?php
if ($HTTP_POST_FILES['type']!="jpg"){ echo "jpg only allowed";} 
else {

$file_name = $HTTP_POST_FILES['ufile']['name'];
$random_digit=rand(00000,99999);
$desh  = ".";
$new_file_name=$random_digit.$desh.$file_name;
$path= "upload/".$new_file_name;
if($ufile !=none)
{
if(move_uploaded_file($HTTP_POST_FILES['ufile']['tmp_name'], $path))
{
echo "Successful<BR/>";
echo "File Name :".$new_file_name."<BR/>"; 
echo "File Size :".$HTTP_POST_FILES['ufile']['size']."<BR/>"; 
echo "File Type :".$HTTP_POST_FILES['ufile']['type']."<BR/>"; 
echo "<img src=\"$path\" width=\"150\" height=\"150\">";
}
else
{
echo "Error";
}
}

}
?>
Member Avatar
mathieu89
Light Poster
37 posts since Nov 2010
Reputation Points: 14 [?]
Q&As Helped to Solve: 4 [?]
Skill Endorsements: 0 [?]
 
0
 

what error message do you get?

Member Avatar
Stefano Mtangoo
Senior Poster
3,713 posts since Jun 2007
Reputation Points: 441 [?]
Q&As Helped to Solve: 394 [?]
Skill Endorsements: 2 [?]
 
0
 

so i got this but its not working

<?php
if ($HTTP_POST_FILES['type']!="jpg"){ echo "jpg only allowed";} 
else {

$file_name = $HTTP_POST_FILES['ufile']['name'];
$random_digit=rand(00000,99999);
$desh  = ".";
$new_file_name=$random_digit.$desh.$file_name;
$path= "upload/".$new_file_name;
if($ufile !=none)
{
if(move_uploaded_file($HTTP_POST_FILES['ufile']['tmp_name'], $path))
{
echo "Successful<BR/>";
echo "File Name :".$new_file_name."<BR/>"; 
echo "File Size :".$HTTP_POST_FILES['ufile']['size']."<BR/>"; 
echo "File Type :".$HTTP_POST_FILES['ufile']['type']."<BR/>"; 
echo "<img src=\"$path\" width=\"150\" height=\"150\">";
}
else
{
echo "Error";
}
}

}
?>

Didn't I give a link with everything you have asked?

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: