Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Displaying Uploaded Files


I currently have a page that allows me to upload files from a User and store them in a dtabase. Once the submit button is pressed, the PHP page appears, and lists the results of the Upload (i.e. Size, Name, Type).

What I am wondering is if there is a way that when I press the submit button ,the actual file that was uploaded will be displayed in the PHP page in addition to the other results so that all can be seen at once? (i.e. a Mind Manager file - .mpp)




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Displaying Php Chart Text On My Host Using An Uploaded Font
Hi im trying to get a chart to display using php. I get an error at the
moment when i use the function (or any requiring an uploaded font to be
used):

imagettftext($image, 6, 0, 0, $initial_point, $colorRed, 'Verdana',
$initial_value);

The error stems from the loading of the verdana ('Verdana') font file
which IS uploaded and works locally but for some reason the script cant
find the file on your site so its returning an error. Does anyonw know
what what might be the cause of this? For example I am using a mac to
work locally and then uploading to the php server which is linuz might
i need to use diferent fonts or something on the server?

Name Uploaded Files
Does anyone know how to change the name of a file as it is uploaded? I think it has something to do with this line: Code: $HTTP_POST_FILES['uploadedFile']['name']; But if I touch the 'name' tag I just get errors.

Renaming Uploaded Files
I'm trying right now to code a "user picture gallery" function into my website. I'm going to have it where when a user creates an account, a directory is created with thier account name as the directory name. This is where all their uploaded pictures will be.

Now, when a user uploades a picture (along with a caption, and the time and date it was uploaded, etc etc), my script will first enter in all this information into a MySQL table.

My question is this: how can I make PHP take the picture that was uploaded and rename it to something like "xxxx.jpg", where xxxx = an automatically incrementing number? The reason I need to do this is in case the user uploads two different pictures that have the same file names (this is going to be quite common, especially now in the age of digital pictures, when everytime you upload pictures from your camera to your computer, it names them the same file names -- like DSC80001.jpg blah blah you get the picture)

How Are Uploaded Files Stored ?
how are uploaded files stored ?...pls show me an example...

How To Rename Uploaded Files Via ID
i have a form that is used as a resume/ picture/ new application uploader
currently the files (resume and picturefile) is being uploaded and renamed via
the applicants firstname-lastname

now my problem is i dont know how to rename the files using ID since the the process
is the files or application must be uploaded first before an ID for that is created
thats why in my current code i used firstname and lastname to rename it
but my problem is if the applicants got the same names so i was thinking of
renaming the files via ID and not firstname-lastname Code:

How To Delete Files Uploaded And Now Owned By PHP
Within homes/ PHP creates a directory, it's an integer such as homes/999 or homes/345. Within that new directory, PHP uploads some graphics, .gif or .jpg.

The problem is, that directory and all those graphics are now "owned" by PHP, usually running as nobody or www. I can't delete them or copy them.

I've tried running a chown() within PHP to make myself the owner, but I get "operation not allowed".

The only solution I've found so far is to set umask(0), so that the directory and graphics have 777 permissions. I don't think that's very safe, though, is it?

Does anyone have any suggestions. I want to be able to delete or copy the files like they are mine, but only me or my group. I'm not running the server myself, but those who are seem willing to work with me.

Problem With Moving Uploaded Files
I am having a little trouble uploading files (html form with post) with
php...

I am trying to copy the file from its temporary upload directory to the
destination directory, however, the server threw this msg at me... what does
it mean? and how do I circumvent it?

$user_file_tmp_name = /tmp/phpTeA9Hs
$dest_name = /home/free3/user_product_images/jamesjiao/Alizee18.jpg

Warning: copy(): open_basedir restriction in effect. File(/tmp/phpTeA9Hs) is
not within the allowed path(s): (/home/free3) in
/home/free3/my-page-admin.php on line 91

I tried both the copy() function and the move_uploaded_file() function and
got the same warning.

Error Deleting Uploaded Files
I have a configuration script which creates a directory on the server, directory used for uploading files. Everything works fine (creation of the directory, uploading) but when I try to delete an uploaded file from this directory using total commander as ftp client I get the following error: "550 Delete operation failed".

The used code is something like this:

$cursuri = "../cursuri";
@mkdir($cursuri, 0777);

Note: if I use total commander "chmod 777 cursuri" I don't get any problems.

Problem With Renaming Files Before Beeing Uploaded.
I'm making a script that renames files (pictures) uploaded by users. All the filenames have to be unique, so if the filename already exists I have to rename it. How do I do that? I tried to use the rename()-function, but that didn't work because both the files in question have be located on the server for rename() to work. That doesn't work for me because all the files is uploaded in the same directory, and you can't have two files with the same name in the same directory without one of them getting overwritten.

So what I need is a script that checks if the file that gets uploaded already exists on the server. if it does, it have to be renamed to someting unique ->before<- it gets uploaded. The names of the already uploded files is stored in a database.

I've made this script, but it doesn't work and I don't know how to make it. The php-script and the uploaded files are in different directories. Anyone have a solution to this problem??

<?

//Connecting to DB
mysql_connect("my hostname","myuser","mypasword");
mysql_select_db("mydb");

//Querying DB
$query = "SELECT picture FROM Ad"; //picture holds the name of the pictures already uploaded
$result = mysql_query($query) or die(mysql_error());

//Checking if the picture alreadey exists in the database
while($i = mysql_fetch_row($result))
{
if($picture_name == $i[0]) //$picture_name is the name of picture the user has uploaded through a form
{

//Removing whitespaces before or after the picture_name
$picture_name = trim($picture_name);

//removing whitespaces in the middle of the picture name
$picture_name = str_replace(" ", "", $picture_name);

//extracting fileextension from the last post in $filext_array
$fileext_array = explode(".",$picture_name);
$fileexst = $fileext_array[count($fileext_array)-1];

//Making the new unique filename using current UNIX timestamp
$unix_time = time();
$new_name = $unix_time.".".$fileexst;

//Renaming filename. Get error on this line: "Warning: Rename failed (No such file or directory)"
rename($picture_name,$new_name); //is it because the picture is not yeat uploaded to the server??
}
}

//Uploading picture to server
$the_path= "/home/kvien/www/club-honda/pictures";

copy($bilde,$the_path . "/" . $bilde_name) or die("Can't copy picture.");

$query = "insert into Ad values ('$name','$membernumber','$picture_name')";
$result = mysql_query($query) or die(mysql_error());
?>

Is_file() Returns False For Uploaded Files?
Running IIS 6 on Windows 2003 server.

After an update to the most recent version of php 5.1.2, for some reacon
a function handling uploaded files using is_file stopped working. is_file
failed for existing files. I fixed it by changing is_file to
file_exists, then it worked again. Prior to the update, in the older
version, presumably it was 5.0.1, is_file worked just fine without
problems.

<?php
echo 'is_file:' . (is_file($_FILES['myfile']['tmp_name']) ? 'true' :
'false');
echo 'file_exists:' . (file_exists($_FILES['myfile']['tmp_name']) ? 'true' :
'false');
?>

<form action="<?php echo $_SERVER['PHP_SELF'] ?>"
enctype="multipart/form-data" method="post">
<input type="file" name="myfile" />
<input type="submit" />
</form>

Submitted a bug report already http://bugs.php.net/bug.php?id=37118

Change File Permissions On Uploaded Files?
I am trying to find a way to change the default file permissions for uploaded files using PHP. When I upload a file using my PHP script the default file permissions are 755. I would like the file to have 744.

Displaying Files In A Folder Using A Calender
I have excel sheets generated daily and weekly in this format for filenames..for daily sheets the filename is Jan-10-2002 (mmm-dd-yyyy) and weekly Week-39-2002. I have a script that uploads to a constant folder all the excel sheets.

Is there a script that can display the daily scripts in form of a calender. I.E a user can choose to view or download the sheet by choosing the date? Also another for displaying weekly excel sheets in a weekly format.

Displaying .txt Files And Maintainint Their Format Using Php
I wish to display .txt files within a php page. I have found out how to do this but any formatting such as paragraphs and tabs is lost. Can anyone help me with how to display the txt file as it is, formatting included? It is simply so we can update our Community Centre website with ease via txt files.

Upload File Error 3: "The Uploaded File Was Only Partially Uploaded"
I've a file that starts like this:

<form id="pdsForm" method="post" action="/mcControlPanel.php"
class="mcForm" charset="UTF-8" enctype="multipart/form-data" >

and it contains this input:

<input id="biopic" name="biopic" type="file" />

The script recieving it does this:

$biopic = $this->core->getVar("biopic");
if (is_array($biopic)) {
print_r($biopic);

I get:

Array ( [name] =L-monkeySmall.jpg [type] =[tmp_name] =[error] =>
3 [size] =0 )

Error 3 is "Array ( [name] =L-monkeySmall.jpg [type] =[tmp_name]
=[error] =3 [size] =0 )". As you can see, 0 kilobytes were
uploaded.

What should I look for? I've been looking on the web for awhile and so
far I've found little useful information about what Error 3 typically
indicates.

Help With Displaying Selecting A Date Range And Displaying Results
I wish to create a simple form that allows the selection of a start date and a stop date with the ability to select what columns to be displayed in the result page.

Getting Name Of File Being Uploaded
i upload a thumbnail and larger picture using a form. i save that in a directory which is chmod 777. i then went to send both of the file names to a database, so the page which display the the thumbnail pictures, pulls the names out of a database and the correlating larger pic for it.

i have the steps correct to get it working but cannot find (due to lack of knowledge) how to figure out how to save the file name. doing it this way so the user does not have to alter file names, they take the pic and upload it. they are done.

Progress Uploaded?
I have an upload page and was wondering if there was a way to add some sort of X percent uploaded? Like some kind of progress indicator? These are such big files that it seems like the computer is freezing up.

Uploaded File Name
Here's what I want:
After uploading the file, I would like to preview the filename and the
original path uploaded from the client side and not what is now
uploaded to the server..

for example, C:mydocumentsmyfilesmyfile.doc
How can I do this?

Uploaded File Ok But Not Created
I'm trying to perform a very simple file upload page and everything seems to go just fine. The $_FILES var is populated with valid data (file size, name, mime type, even from a win remote computer) but the file just doesn't exists... It points to /tmp/php[random garbage] but there's no file starting with 'php'. /tmp is world-writeable so I don't see what the problem is. PHP Code:

Deleting Uploaded File
I am using a from in which users enter data as well as upload a file. I also give them an opportunity to delete their entry. Currently I am deleting the entry from the database.

Can't Replace Uploaded File
I have the following problem, I have a database (MySQL) in which I can store filenames, in my script I can select a file from my hard drive that will be uploaded and stored in a directory on the server. So far so good.

Now when I want to replace the file by another one and use the same script it won't replace the file. Does anybody outthere know what the problem might be??

The following code is my part of the script that does the uploading:

if ($img1_name != "") {

copy("$img1", "/home/sitename/www/dbasepictures/$img1_name") or die ("Couldn't copy the file!");

} else {

die("No input file specified");
}

Resizing An Uploaded Image
I finally figured out how to upload an image through an HTML form using PHP. I have the image in a directory. Now, the hard part - how do I take that imae ($photo) and resize it and save it as two different images - a thumbnail that is 75x50 and a full image that is 150x100.

Downloading An Uploaded .doc File
I am working on a site in which some members may browse/upload a Word document and other members may wish to download these and view them. I have tried saving the uploaded file like..

if (!copy($cv, "cvs/cv".$cid.".doc") ) {
echo("Problems encountered receiving your CV. However your application will still be processed.");}

and the download link like...

<A HREF='<?="/cvs/cv$cid.doc"?>'><B>View</B></A>

..and the browser opens Word and the file gets displayed. This is taking FAR to long to happen. What would be ideal is to simply click on the link and get the normal download dialog up. I also tried..

if (!copy($cv, "cvs/cv".$cid) ) {
...} and to view..

<A HREF='<?="/cvs/cv$cid"?>'><B>View</B></A>

..but I got a download dialog asking if I wanted to download CVxxx.txt but I need CVxxx.doc. Any ideas? I want to be prompted to download a Word Doc.

Mimetype Of An Uploaded File?
can anyone please help me on the mimetype of an uploaded file?

if i upload a jpg using IE, the mimetype showed by
$_FILES['filename']['type'] is "image/pjpeg" but if I use the same
script in Firefox, the mimetype shows "image/jpeg". Same with
uploading png files, in IE the mimetype shows "image/x-png", in
Firefox, it shows "image/png".

Can anyone please tell me why this difference occurs and how to get
rid of this? I am concerned because below is my code, this code works
fine in firefox but not in IE because of the changed mimetype.

$mimetype = $_FILES['imagefile']['type'];
$temporary_name = $_FILES['imagefile']['tmp_name'];
switch($mimetype) {
case "image/jpg":
$i = imagecreatefromjpeg($temporary_name);
break;
case "image/jpeg":
$i = imagecreatefromjpeg($temporary_name);
break;
case "image/gif":
$i = imagecreatefromgif($temporary_name);
break;
case "image/png":
$i = imagecreatefrompng($temporary_name);
break;
}

When I echo the $mimetype, i can see the different mimetypes in
different browser.

Resizing Uploaded Images
I want to have an option on my site to upload images. I then want to have PHP (or something) make a thumbnail version of the image automatically. Is this possible and how?

E-mail Uploaded File!
I want to create a form for the user to upload one file. I don't want to
store the file on the server... I want to email it!

Resizing A File That Has Been Uploaded
I am using a standard form to upload a file, but I want to resize it
before I store it.

I have this part

move_uploaded_file($_FILES['picture_name']['tmp_name'],
'images/foo.jpeg');

I do not know what to put for $source_jpeg in...
imagecopyresampled($image_dest, $source_jpeg, 0, 0, 0, 0, $new_width,
$new_height, $width_orig, $height_orig);

Overwrite Image That Was Already Uploaded
When a user uploads an image from a form, the image is loaded to a directory on my server.  If the user uploads an image with the same filename as one that already exists in the uploaded folder, they receive this error:

Warning: copy(image path/image name.jpg) [function.copy]: failed to open stream: Permission denied in /var/www/uploadpage.php on line 22

Is there a way to hide this error or to allow the user to overwrite the existing image?

Overwrite Uploaded Photo
i;m using this code to upload photos it works great basic but great, what i want to do is when a user uploads a photo the previuos one is deleted, i tried a few unlink codes but it never workjed out, Code:

Moving Uploaded File
I am trying to make a simple file upload page. It will not move the file properly. It only spits out the error message. Here's the code:

How To Tell User Where File Was Uploaded Too?
how can you inform the user one where their uploaded file has gone too (including the filename)? Here is my script which uploads to "/images/":

<?php
session_start();

$storage = 'images/';

$now= date("Y-m-d_Gis_");

$uploadfile = "$storage/" . basename( $now.$_FILES['Filedata']['name'] );
//$uploadfile = "$storage/" . basename( $_FILES['Filedata']['name'] );

if ( move_uploaded_file( $_FILES['Filedata']['tmp_name'] , $uploadfile ) ) {
echo( '1 ' . $_FILES['Filedata']['name']);
}else{
echo( '0');}
?>
I have tried inserting the following on the file upload confirmation page but it doesn't seem to show the link:

<a href = "<?php echo $_SESSION['name']; ?>">

Altering Name Of Uploaded File
I have a site that lets users uploads photos. I want to add on the user's username to the filename incase another user uploads the same filename.
$smallpics = './smallpics/'.$_FILES['file']['name'].'$user';   $user is the username. it doesn't work as it takes it as a new directory.

Uploaded Image Has Black Bar
I was wondering if anyone has ever encountered a problem with an uploaded and resized image that now has a black bar on the right side of the image?

The image is uploaded and resized properly via a form, however the right 10% of the image is black.

Uploaded File - Filesize Doubles !
I have an upload scipt which is working fine...or so i thought. I found out the original filesize actually doubles when it gets uploaded into my server..

Uploaded File Is Not Returning An Error
I've set up a file upload script for my users. When a user uploads a file that is larger than the max_post_size, the script runs for an unusually long time and fails to set any errors in the $_FILE array. An upload that is larger than max_file_size and less than max_post_size will generate errors as expected. It appears that the script fails to finish reading the post data and continues to churn along. If anyone has experienced this issue before, I would greatly appreciate some advice.

For what it is worth:
IIS 5 Win2k Server
PHP 4.3.9

Rename Uploaded Images With Set Pattern
I have an upload script, but it keeps the files original name. What i would really like to happen is for each file to be named something like this.

imagecatagory_1.jpg
imagecategory_2.jpg
imagecategory_3.jpg

And is there a way to take into account which images are currently in the directory? Like if there already _1 _2 and _3 in the directory and you send 2 more files it knows to name them _4 and _5 ??? PHP Code:

PHP Upload - Rename Uploaded File
I have to allow my visitors to upload image on my site.

I am using the follwoing code to do that:

$uploaddir = 'admin/'
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile);

My problem is that I expect them to use same file name, like all of
them will be uploading files like, comments.rtf. So if there is already
one comments.rtf the file will get overwriten... so the challenge is to
rename the files to username-filename.rtf

can anybody here will take the pain to modify this code, I will be
thankful, or please guide to me some tutorial where they are dealing
with simple code and not with advanced classes.

Getimagesize() Of Client Image To Be Uploaded
just wondering if it is possible to get the height and width of an image a user is about to upload. Im thinking i would have to use getimagesize() and apply it to $image (from $image posted in file form orbject). right?

im using this in a preview image script, which works but i want the window to be the same size as image using javascript window.open. right now it opens in a preset window width and height.

Viewing Uploaded Word Document?
I am working on a recruitment site and have the option for folks to browse and upload their CV/Resume if a candidate likes the look of a job. The CVs go into a cvs folder.
When an employer logs in to check the applicants for the job I want to create a link to the respective CV. The link is: <A HREF='<?="cvs/cv".$visitor?>'><B>CV</B></A>

but this views the file in the default text editor and comes out garbled if the cv is a .doc. I have tried <A HREF='<?="cvs/cv".$visitor.".doc"?>'><B>CV</B></A>

to try and launch Word but I get a 404 file not found. The same goes for .rtf. I'm probably missing something obvious.

Php Script That Displays Last Uploaded Jpg In A Directory
As title really, does anyone know of (or could write?) a php file which
in a directory of .jpg files display the most recent added to that
/dir?

How To Change Name Of Uploaded Image File?
I'm using the following script to upload an image to my server. It uses the script: fileupload-class.php:

<snipped url>

It's working fine except it uses the uploaded file name when placing the file into my web server folder. I would like to change the filename before it is copied to the folder.

I've tried everything to figure out how this is done. I've had no luck. Would someone be able to tell me where in the script I can change the name of the file before it is copied into the folder on my server? (i.e., agent_image_001.gif)

<?php
require("fileupload-class.php");
$path = "agent_images/";
$upload_file_name = "userfile";
$acceptable_file_types = "image/gifs";
$default_extension = "gif";
$mode = 1;
if (isset($_REQUEST['submitted'])) {
$my_uploader = new uploader($_POST['en']);
$my_uploader->max_filesize(20000); // 20 kb
$my_uploader->max_image_size(200, 150); // max_image_size($width, $height)
if ($my_uploader->upload($upload_file_name, $acceptable_file_types, $default_extension)) {
$my_uploader->save_file($path, $mode);
}
.........

Validate Uploaded File's Filename
I use the code below as part of my file upload validation process, it checks that the filename has no illegal characters. PHP Code:

How To Read Uploaded File In Chunks Using PHP?
I need to read an uploaded file into chunks, so I can examine the acculative size between chunks to
determine if a maximum size is being exceeded. I'm currently using the PHP function
"move_uploaded_file()" to move it in one piece. But, I'm finding some clients files are bigger than
I want to allow, and with that function I don't have an opportunity to determine that until the
entire file has been uploaded.

Acquiring Value Of Primary Key From Uploaded File
I have a PHP file upload feature that also gives the user the option to
assign more than 1 project association to the file. The file's name, title,
primary project, etc. is inserted into a document link table in a MySQL db
after the file is uploaded. The secondary (and multiple) project(s) are also
selected using a separate list box (there are 2 boxes - one for the primary
project, and one for any/all associated projects) The selected values from
the secondary box need to be inserted into a junction table that reflects
both the id for the newly uploaded file and the secondary project(s) - with
a primary key for the association itself, i.e,:

assoc_id doc_id proj_id
1 265 5
2 265 3
3 265 1

I would use a foreach statement to pull the projects from the select list,
but how do I get the newly generated doc_id in order to pass that value to
the association table? Can I assign it a variable at the same time I insert
the data into the primary table? The ID is auto-incremented and is inserted
into the primary table as follows:

$tool_insert = "INSERT INTO tools VALUES ('', '$uploadedname', '$tooltitle',
'$tooldesc', '$tooltype_id', '$toolcat_id', '$primeproj_id', '$location')";

How Can I Check If A File Is Completely Uploaded...???
i've created an application for a customer where the customer can upload
..csv-files into a specified ftp-directory. on the server, a php-script,
triggered by a cronjob, reads all the data, imports it into a mySQL database
and deletes the .csv-file after the import.

so far, so good.

but in some cases the cronjobs starts running when the file is not completely
uploaded. so a part of the data is truncated. :-(

is there any method in php to check if a file is completely uploaded via ftp
or not? i didn't find anything about this on php.net and it would be great if
someone could help me with this problem.

Move Uploaded File Problem
I'm using move_uploaded_file function to upload images. it can work properly for gif, jpg, png and etc format. but it appear to have problem when upload bitmap images. the bitmap image cannot be uploaded.. why this happen?

Using PHP To Compile Uploaded Sourcecode With Cygwins Gcc?
I have an intresting problem: I want to let users upload sourcecode
and then compile it using my cygwin gcc... But one thing at a time... I
can't get that gcc to execute...

shell_exec("gcc temp.c"); # Doesn't work as that will use MinGW
shell_exec("D:cygwiningcc.exe temp.c"); /* Gives some error about dll
stuff (procedure not found I think)*/

So my next though was to open "bash.exe --login -I" and fwrite the
commands... But that still tries to use the mingw compiler it seems...Guess
there's some environiment problem... So I figured I could use virtual() to a
cgi script with this as first line:
#!D:/cygwin/bin/perl
and then use the perl open(), with |/cygdrive/d/bin/gcc.exe temp.c as
argument... Seems like it executes the right compiler then, but then I get
millions of errors caused by *.h can't be opened (yes, the source tries to
include them), so I though about passing -B /usr/include to it... But those
errors still appear... Also, it feels somewhat bad to use virtual() to call
perl scripts, so I was wondering if you ppl have some nice idea on how I
would do it?

Paths:
Cygwin: d:cygwin
PHP: C:PHP (4.3.3, zip from php.net, installed as Apache 1.3.28 module)
Apache: D:Apache (installed using .msi package, as service)
Perl: D:perlinperl.exe (or D:cygwininperl.exe)
Script: D:www2compile.php, D:www2compilingcompile_cyg.cgi
Sourcecode: D:www2compiling emp.c (yes, only one file yet, that's a later
problem)

pwd returns I'm in the 'compiling' folder, in the php script, I chdir() to
get into that folder...

Retrieving And Showing Uploaded Images
I have recently spent hours adding a register / login script to my website. Since i'm a newbie to PhP it took me alot of time and coffee to get it sorted. So here I am at another roadblock. I want to be able to let my logged in users upload pictures (JPG's and relatively small file sizes) and then these pictures to appear on their own profile page.

View Uploaded Images Of Different Dates
iam using the following code to view the uploaded images.
i can select the 2 different dates and can see the uploaded images between these 2 different dates.i can also delete those images also.but it is working good on localhost.but when i upload the script on server,it is not displaying the images between 2 different dates which i select,it just displays todays uploaded images. Code:


Copyright © 2005-08 www.BigResource.com, All rights reserved