View Full Version : Resolved images on file extentions... Need help!
auriaks
11-04-2009, 10:14 PM
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
djr33
11-04-2009, 11:24 PM
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:
$extimgs = array(
'jpg' => '1.jpg',
'gif' => '2.jpg'
)
Find the image, display it wherever you'd like.
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.
auriaks
11-05-2009, 08:05 PM
My form:
<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>
My php for storing:
<?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");
}
?>
Can you change it?? :) Thx
djr33
11-06-2009, 04:29 AM
$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.
}
Print out the image within an image tag or whatever you want.
auriaks
11-06-2009, 07:58 PM
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)
<?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");
}
?>
I tried so many ways to put your script in this, but all i got was EMPTY uploader_talpykla.php window. :confused:
BTW, i stored pictures in 'src/pic.jpg'. its one of 5 pictures i have.
djr33
11-07-2009, 12:08 AM
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.
auriaks
11-07-2009, 12:17 AM
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.
auriaks
11-07-2009, 03:09 AM
i solved extension problem, but still one smller appeared...
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>
";
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:
TEXT
TEXT
TEXT
i need:
TEXT TEXT TEXT
Thanks...
bluewalrus
11-07-2009, 03:30 AM
Take out the <br>'s
auriaks
11-07-2009, 03:50 AM
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
bluewalrus
11-07-2009, 05:04 AM
Can you post the full code your using to produce that?
auriaks
11-07-2009, 05:26 AM
<?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
fg123
11-10-2009, 01:15 AM
Remove all of the <br>'s
thetestingsite
11-10-2009, 01:38 AM
Try this:
<?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>
Change the number in red above to however many images you want to display across. The above is not tested, but should work.
Hope this helps.
auriaks
11-10-2009, 06:08 PM
@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.
auriaks
11-11-2009, 12:11 AM
it works! THANKS :)
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.