473,320 Members | 1,955 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Setting up file uploads with php

Heya guys, i got this simple script to work and now it doesnt.Its far from completed, i know, i just want it to gogogo so i can expand it to include my preferences and a few hidden fields.
I can't tell if i screwed up the code or its a server related problem. here goes....


Expand|Select|Wrap|Line Numbers
  1.  <html> 
  2. <body>
  3. <form action="upload.php" method="post" ENCTYPE="multipart/form-data"> 
  4. <input type="file" name="file" size="30" /> 
  5. <input type="submit" value="gogogo" /> 
  6. </form> 
  7. </body>
  8. </html>
  9.  
[PHP]
$uploaddir = "/var/www/html/gallery";
if(is_uploaded_file($_FILES['file']['tmp_name']))
{
move_uploaded_file($_FILES['file']['tmp_name'],$uploaddir.'/'. $_FILES['file']['name']);
};
echo "Completed";

[/PHP]
Mar 29 '07 #1
13 2019
ak1dnar
1,584 Expert 1GB
[PHP]$uploaddir = "/var/www/html/gallery"; [/PHP]
remove "/" from the beginning of the path and put a "/" to the end check it.
[PHP]$uploaddir = "var/www/html/gallery/"; [/PHP]

if your files are listed with gallery folder {all are in same DIR} simply this also work.
but make sure to assign the write permission to the folder if its remote server.

[PHP]$uploaddir = "gallery/"; [/PHP]
Mar 29 '07 #2
thanx for you're input ajax, i tried the different variations but to no avail, (on a remote server btw). it seems such a simple script.

[directories and permissions]

/ -- var -- 755 / www-- 755 / html -- 755 | -- gallery -- 777
| -- form.php -- 755
| -- upload.php -- 755
I just noticed that my phpinfo() returns upload_tmp_dir = novalue but file_uploads = On. is that correct?
Mar 29 '07 #3
ak1dnar
1,584 Expert 1GB
thanx for you're input ajax, i tried the different variations but to no avail, (on a remote server btw). it seems such a simple script.

[directories and permissions]

/ -- var -- 755 / www-- 755 / html -- 755 | -- gallery -- 777
| -- form.php -- 755
| -- upload.php -- 755
I just noticed that my phpinfo() returns upload_tmp_dir = novalue but file_uploads = On. is that correct?
Put your form.php,upload.php and gallery in side one dir we will say www dir.then set your variable like this.
[PHP]$uploaddir = "gallery/"; // Note only single "/"[/PHP]

make sure to set 777 for gallery dir and give it a try again.
and remove the file size="30" from the form for now.
Mar 29 '07 #4
[quote=ajaxrand]Put your form.php,upload.php and gallery in side one dir we will say www dirQUOTE]
thx ajax, but my root.dir is html. i put them i a subfolder, rechecked my permissions, still no go. tried the new path, still no go, tried variations of the path, still no go. its hard to believe it actually worked.
Mar 29 '07 #5
ak1dnar
1,584 Expert 1GB
[quote=jungabunga]
Put your form.php,upload.php and gallery in side one dir we will say www dirQUOTE]
thx ajax, but my root.dir is html. i put them i a subfolder, rechecked my permissions, still no go. tried the new path, still no go, tried variations of the path, still no go. its hard to believe it actually worked.
Sorry I didn't get u.Is it working or Not?
Mar 29 '07 #6
no sry, no good so far
Mar 29 '07 #7
ak1dnar
1,584 Expert 1GB
Try this one just execute this after creating directory named myfiles with 777.
put php script and myfiles folder in same place.

[PHP]<?php
$target_path = "myfiles/"; //Directory Name to Upload
if($_POST['upload'])
{
$newName = md5(basename($_FILES['upload_fle']['name']));
$ext = strrchr(basename($_FILES['upload_fle']['name']), ".");
$fullName = $newName.$ext;

if(move_uploaded_file($_FILES['upload_fle']['tmp_name'], $target_path.$fullName))
{
echo "The file ". basename( $_FILES['upload_fle']['name']).
" has been uploaded with this name : ".$fullName;
} else
{
echo "There was an error uploading the file, please try again!";
}

}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<form action="<? echo $PHP_SELF; ?>" method="post" enctype="multipart/form-data" name="frmAlbum" id="frmAlbum">
<input name="upload_fle" type="file" id="upload_fle"/>
<BR>
<input name="upload" type="submit" value="Upload">
</form>
</body>
</html>[/PHP]
Mar 29 '07 #8
cheers, but i got the

There was an error uploading the file, please try again!
Mar 29 '07 #9
ak1dnar
1,584 Expert 1GB
This script is working in my web server. even your one also working. if it is not working in your end its your bad luck.BTW what type of files you tried to upload.
Don't go for massive files, just upload simple text files first of all. there are limitation for huge files from the php level.
Mar 29 '07 #10
yeah im only trying small files. i wonder what i did. i might just reinstall web then, thx for the persistance dude.
Mar 29 '07 #11
ak1dnar
1,584 Expert 1GB
yeah im only trying small files. i wonder what i did. i might just reinstall web then, thx for the persistance dude.
Don' t give up, give it a try. hope you will get the solution. ;)
Mar 30 '07 #12
Don' t give up, give it a try. hope you will get the solution. ;)
I musta screwed up the permissions on teh server or something. i resinalled my micro version of fedora and it works fine now :P
Mar 30 '07 #13
ak1dnar
1,584 Expert 1GB
I musta screwed up the permissions on teh server or something. i resinalled my micro version of fedora and it works fine now :P
Great work.. :) c u l8r.
Mar 30 '07 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: kafooey | last post by:
Hi all, I've been digging around on the newsgroups and the web for a possible answer for this problem, but have so far come up with nothing so thought I would ask here... I have the following...
13
by: Sky Sigal | last post by:
I have created an IHttpHandler that waits for uploads as attachments for a webmail interface, and saves it to a directory that is defined in config.xml. My question is the following: assuming...
5
by: Kikoz | last post by:
Hi all. I assume that if the user uploads a file from aspx page IIS will put all future requests to the same page from other users in a line and all of them will be waiting until this upload...
1
by: John | last post by:
Hi all, How do I programmatically save an uploaded file (using the File Field control) to a sub folder of a web site. I've tried specifying ..SaveAs("~Uploads/" & "fielname") but it keeps...
4
by: yehaimanish | last post by:
I am developing the project management system. Each Project: 1. Title, description ... , stored in mysql database 2. Upto ten files (initial description), (name in db, file in file system) 3....
1
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
3
by: markus.rietzler | last post by:
i want to do (multiple) file upload(s) and display a progress bar. with firefox and safari it is no problem at all. only IE makes some problems. my script is based on ajax-uploader, which can be...
6
by: Emmanuel Petit | last post by:
First of all I am rather new into PHP. I use php 5 and I am putting together a web site for a local association I belong too. Most of the site is okay, except for this problem : I need to be...
6
by: Milan Krejci | last post by:
while(list($key,$value) = each($_FILES)) { if(!empty($value)){ $filename = $value; $add = "upimg/$filename"; echo $_FILES; $error=copy($_FILES, $add); if (!$error)...
10
by: =?ISO-8859-1?B?UOlw6g==?= | last post by:
Hello. Im new to php and i had experience in ASP. IM trying to get a pdf file from a remote folder and what happens is that opens a new page. Here is the code: <a...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.