Hi, i have an idea to create php script which regonises the uploaded file extention. What is more, if my file was xxx.txt then it will show picture 1, if xxx.png - picture 2, if xxx.zip - picture 3 and etc. If you need more info, ASK :) Thanks a LOT
Printable View
Hi, i have an idea to create php script which regonises the uploaded file extention. What is more, if my file was xxx.txt then it will show picture 1, if xxx.png - picture 2, if xxx.zip - picture 3 and etc. If you need more info, ASK :) Thanks a LOT
Set up a normal file uploads script.
Once you do this, the filename will be available as a variable in PHP. Using this, you can just split the string and get whatever is after the ., so jpg, gif, etc. (substr(), for example).
As for "displaying" an image, you just need to set up an array with filetypes to images:
Find the image, display it wherever you'd like.PHP Code:$extimgs = array(
'jpg' => '1.jpg',
'gif' => '2.jpg'
)
If you need more specific information you will need to show us code or tell us exactly where you want the image to show up, how you will access the filename, etc.
My form:
My php for storing:PHP Code:<form enctype="multipart/form-data" action="redirect_upload/uploader_talpykla.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="10000000" />
<span style="font-size: 10.0pt; font-family: 'Times New Roman',serif">
Send us: <input name="uploadedfile" type="file" />
<input type="submit" value="Siųsti" /><br>
</span>
</form>
Can you change it?? :) ThxPHP Code:<?php
// Where the file is going to be placed
$target_path = "talpykla/";
/* Add the original filename to our target path.
Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
//Checking
$target_path = "talpykla/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
header("location:up_yes1.php");
} else{
header("location:up_no1.php");
}
?>
Print out the image within an image tag or whatever you want.PHP Code:$name = basename( $_FILES['uploadedfile']['name']); //this is the variable you want
$ext = substr($name,strrpos($name,'.')); //get the part after the last .
$images = array( //setup an array of exts=>images
'jpg' => 'jpeg.gif',
'gif' => 'mygifimage.gif',
... //add as many as you need
'pdf' => 'documentimage.gif'
); //ok, that's setup
if (isset($images[$ext])) { //is the file extension valid, do we have an image?
echo $images[$ext]; //it will print out jpeg.gif for ext .jpg, etc.
}
Thank you :) I think it will work, but idk where to put your script... in my uploading file or other which i use to show the file's picture?
my full uploading script: (uploader_talpykla.php)
I tried so many ways to put your script in this, but all i got was EMPTY uploader_talpykla.php window. :confused:PHP Code:<?php
// Where the file is going to be placed
$target_path = "talpykla/";
/* Add the original filename to our target path.
Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
//Checking
$target_path = "talpykla/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
header("location:up_yes.php");
} else{
header("location:up_no.php");
}
?>
BTW, i stored pictures in 'src/pic.jpg'. its one of 5 pictures i have.
You are sending out a header to change the location-- a redirect. Of course nothing will show up on the page. Remove header("location:up_yes.php"); and replace it with my code. That will just display the image, though. But if you want something more, you will have to redesign your site.
i tried this... - empty page :D Maybe i need those pictures to be shown in next page. I thought about saving name into mysql variable and call it in the next page. but idk how to use your script then.
i solved extension problem, but still one smller appeared...
This is my script for writing info from mysql to webpage. Here's the problem: It writes information 3 times in one column, but i need them horizontal... now its like:PHP Code:echo "
<table width='120px';>
<tr>
<td>
<img src='redirect_upload/uploads/$filename' width='80px' height='70px' border='0'>
<font size='0.8' face='Verdana' color='blue'><b>
Pavadinimas: $name <br>
Idejo: $nick <br>
Data: $date <br>
Rusis: $type
</b></font>
</td>
</tr>
</table>
";
TEXT
TEXT
TEXT
i need:
TEXT TEXT TEXT
Thanks...
Take out the <br>'s
i mean else :D now it is :
picture
text
text
text
picture
text
text
text
picture
text
text
text
i want:
picture picture picture
text text text
text text text
text text text
my command repeats all the script 3 times
Can you post the full code your using to produce that?
PHP Code:<?php
include('db_conn.php');
$queryget = mysql_query("SELECT * FROM xxx ORDER BY `date` LIMIT 3") or die("Error with query");
while ($row = mysql_fetch_array($queryget))
{
$name = $row['name'];
$type = $row['type'];
$nick = $row['nick'];
$format = $row['format'];
$filename = $row['filename'];
$date = $row['date'];
echo "
<table width='120px';>
<tr>
<td>
<img src='redirect_upload/$format' width='80px' height='70px' border='0'>
<font size='0.8' face='Verdana' color='blue'><b>
Pavadinimas: $name <br>
Idejo: $nick <br>
Data: $date <br>
Rusis: $type
</b></font>
</td>
</tr>
</table>
";
}
?>
To clarify, your issue is that you want to see:
http://localhostr.com/files/9614e8/capture.png
And not:
http://localhostr.com/files/b94c9a/capture.png
Remove all of the <br>'s
Try this:
Change the number in red above to however many images you want to display across. The above is not tested, but should work.Code:<?php
include('db_conn.php');
$queryget = mysql_query("SELECT * FROM xxx ORDER BY `date` LIMIT 3") or die("Error with query");
$count = 0;
?>
<table width="120px">
<tr>
<?php
while ($row = mysql_fetch_array($queryget)) {
/* I am not getting rid of these assigned variables just in case you use them later in the script */
$name = $row['name'];
$type = $row['type'];
$nick = $row['nick'];
$format = $row['format'];
$filename = $row['filename'];
$date = $row['date'];
?>
<td>
<img src='redirect_upload/<?php echo $row['format'];?>' width='80px' height='70px' border='0'>
<font size='0.8' face='Verdana' color='blue'><b>
Pavadinimas: <?php echo $row['name'];?> <br>
Idejo: <?php echo $row['nick'];?> <br>
Data: <?php echo $row['date'];?> <br>
Rusis: <?php echo $row['type']; ?>
</b></font>
</td>
<?php
echo ($count % 3) ? '</tr><tr>' : '';
$count++;
}
?>
</tr>
</table>
Hope this helps.
@fg123
<br>'s just manage looking of my image and text, but everything is in while and it will do 3 times. you cant change the way how they will look in webpage by deleting <br>'s
Auriak, please take a look at mine and thetestingsite's posts above.
it works! THANKS :)