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, ASKThanks a LOT
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, ASKThanks a LOT
Last edited by auriaks; 11-11-2009 at 12:13 AM.
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.
Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
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??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_yes1.php");
} else{
header("location:up_no1.php");
}
?>Thx
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.
}
Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
Thank youI 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.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.
Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
i tried this... - empty pageMaybe 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 elsenow 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
Bookmarks