vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   File Uploader (https://vborg.vbsupport.ru/showthread.php?t=106299)

Jaynesh 01-25-2006 03:50 PM

File Uploader
 
Im learning PHP and came up with this script from a tutorial..

Code:

<?php
if(isset($_FILES['file']) == false OR $_FILES['file']['error'] == UPLOAD_ERR_NO_FILE) {
die('Error');
}
if($_FILES['file']['error'] != UPLOAD_ERR_OK) {
die('Error Uploading');
}

$path = '/home/vekaria/public_html/imagehosting/';

$file = $path . $_FILES['file']['name'];
move_uploaded_file($_FILES['file']['name'], $newfile);

die('Done');
?>

It is a file uploader,

How can i make it so when i upload an image it will display the image after it has been uploaded.

Cole2026 01-26-2006 01:05 AM

PHP Code:

<?php
if(isset($_FILES['file']) == false OR $_FILES['file']['error'] == UPLOAD_ERR_NO_FILE
{
die(
'Error');
}
if(
$_FILES['file']['error'] != UPLOAD_ERR_OK
{
die(
'Error Uploading');
}

$path '/home/vekaria/public_html/imagehosting/';

$file $path $_FILES['file']['name'];
move_uploaded_file($_FILES['file']['tmp_name'], $file);

// get ext
$ext substr(strrchr($_FILES['file']['name'], '.'), 1);

// make img array
$imgexts = array('jpg','jpeg','gif','png','jfif','bmp');

if ( 
in_array($ext$imgexts) )
{
    die(
'<img src="' $path $_FILES['file']['name'] . '" />');
}
else
{
     die(
'Done');
}
?>

Here's something simple you can do.

Jaynesh 01-26-2006 06:42 AM

Im getting this error :(

Parse error: parse error, unexpected T_STRING in /home/vekaria/public_html/learning.php on line 27

Could you please explain what it means and how to fix it?

Cole2026 01-26-2006 07:25 PM

Quote:

Originally Posted by Jaynesh
Im getting this error :(

Parse error: parse error, unexpected T_STRING in /home/vekaria/public_html/learning.php on line 27

Could you please explain what it means and how to fix it?

I was in a rush, forgot to close the die tag.

I updated the tag in my post, it should parse correctly now.

By the way, the "unexpected T_STRING" parsing error usually means you didn't close a function correctly.

Jaynesh 01-27-2006 03:08 PM

Thanks, worked perfect :)

One last thing :) How can i have it so when an image is uploaded it will also display the link to it aswell.. i tried this ..

Code:

<?php
if(isset($_FILES['file']) == false OR $_FILES['file']['error'] == UPLOAD_ERR_NO_FILE) 
{
die('Error');
}
if($_FILES['file']['error'] != UPLOAD_ERR_OK) 
{
die('Error Uploading');
}

$path = '/home/vekaria/public_html/imagehosting/';
$path2 = 'http://www.lyricalsoundz.com/imagehosting/';

$file = $path . $_FILES['file']['name'];
move_uploaded_file($_FILES['file']['tmp_name'], $file);

// get ext
$ext = substr(strrchr($_FILES['file']['name'], '.'), 1);

// make img array
$imgexts = array('jpg','jpeg','gif','png','jfif','bmp');

if ( in_array($ext, $imgexts) )
{
    die('<img src="' . $path2 . $_FILES['file']['name'] . '" />');
}
{
print $path2 . $_FILES['files']['name'];
}
?>

but it only displays the link for anything that is NOT an image, i want it to also apear when an image is uploaded aswell.

Okay ive managed to get it to display the link but having trouble linking the image to do the url.

it just doesnt display when i view the source its there...

Code:

<?php
if(isset($_FILES['file']) == false OR $_FILES['file']['error'] == UPLOAD_ERR_NO_FILE) 
{
die('Error');
}
if($_FILES['file']['error'] != UPLOAD_ERR_OK) 
{
die('Error Uploading');
}

$path = '/home/vekaria/public_html/imagehosting/';
$path2 = 'http://www.lyricalsoundz.com/imagehosting/';

$file = $path . $_FILES['file']['name'];
move_uploaded_file($_FILES['file']['tmp_name'], $file);

// get ext
$ext = substr(strrchr($_FILES['file']['name'], '.'), 1);

// make img array
$imgexts = array('jpg','jpeg','gif','png','jfif','bmp');

if ( in_array($ext, $imgexts) )
{
    echo ('<img src="' . $path2 . $_FILES['file']['name'] . '" /> <br />');
}
if ( in_array($ext, $imgexts) )
{
echo ('<a href="' . $path2 . $_FILES['file']['name'] . '" >');
}

?>

Okay my mistake, i fixed it and its working :) wow im getting good at this.

here it is..

Code:

<?php
if(isset($_FILES['file']) == false OR $_FILES['file']['error'] == UPLOAD_ERR_NO_FILE) 
{
die('Error');
}
if($_FILES['file']['error'] != UPLOAD_ERR_OK) 
{
die('Error Uploading');
}

$path = '/home/vekaria/public_html/imagehosting/';
$path2 = 'http://www.lyricalsoundz.com/imagehosting/';

$file = $path . $_FILES['file']['name'];
move_uploaded_file($_FILES['file']['tmp_name'], $file);

// get ext
$ext = substr(strrchr($_FILES['file']['name'], '.'), 1);

// make img array
$imgexts = array('jpg','jpeg','gif','png','jfif','bmp');

if ( in_array($ext, $imgexts) )
{
    echo ('<img src="' . $path2 . $_FILES['file']['name'] . '" /> <br />');
}
if ( in_array($ext, $imgexts) )
{
echo ('<a href="' . $path2 . $_FILES['file']['name'] . '" >Image URL</a>');
}

?>

Any suggestions to make it shorter ?


All times are GMT. The time now is 06:16 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01831 seconds
  • Memory Usage 1,740KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (4)bbcode_code_printable
  • (1)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete